Skip to content

Commit

Permalink
Introduction of baseTx (#128)
Browse files Browse the repository at this point in the history
* added basetx

* test fix

* better coding

* getter for V

* small fixes

---------

Co-authored-by: Goran Rojovic <[email protected]>
  • Loading branch information
dusannosovic-ethernal and goran-ethernal authored Mar 6, 2024
1 parent 3fe26ca commit e5d5a9b
Show file tree
Hide file tree
Showing 37 changed files with 636 additions and 746 deletions.
54 changes: 32 additions & 22 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,11 @@ func TestBlockchainWriteBody(t *testing.T) {
t.Parallel()

tx := types.NewTx(&types.LegacyTx{
Value: big.NewInt(10),
V: big.NewInt(1),
From: addr,
BaseTx: &types.BaseTx{
Value: big.NewInt(10),
V: big.NewInt(1),
From: addr,
},
})

block := &types.Block{
Expand Down Expand Up @@ -623,8 +625,10 @@ func TestBlockchainWriteBody(t *testing.T) {
t.Parallel()

tx := types.NewTx(&types.LegacyTx{
Value: big.NewInt(10),
V: big.NewInt(1),
BaseTx: &types.BaseTx{
Value: big.NewInt(10),
V: big.NewInt(1),
},
})

block := &types.Block{
Expand Down Expand Up @@ -655,8 +659,10 @@ func TestBlockchainWriteBody(t *testing.T) {
t.Parallel()

tx := types.NewTx(&types.LegacyTx{
Value: big.NewInt(10),
V: big.NewInt(1),
BaseTx: &types.BaseTx{
Value: big.NewInt(10),
V: big.NewInt(1),
},
})

block := &types.Block{
Expand Down Expand Up @@ -715,8 +721,8 @@ func Test_recoverFromFieldsInBlock(t *testing.T) {
},
}

tx1 := types.NewTx(&types.LegacyTx{Nonce: 0, From: addr1})
tx2 := types.NewTx(&types.LegacyTx{Nonce: 1, From: types.ZeroAddress})
tx1 := types.NewTx(&types.LegacyTx{BaseTx: &types.BaseTx{Nonce: 0, From: addr1}})
tx2 := types.NewTx(&types.LegacyTx{BaseTx: &types.BaseTx{Nonce: 1, From: types.ZeroAddress}})

computeTxHashes(tx1, tx2)

Expand Down Expand Up @@ -745,9 +751,9 @@ func Test_recoverFromFieldsInBlock(t *testing.T) {
},
}

tx1 := types.NewTx(&types.LegacyTx{Nonce: 0, From: types.ZeroAddress})
tx2 := types.NewTx(&types.LegacyTx{Nonce: 1, From: types.ZeroAddress})
tx3 := types.NewTx(&types.LegacyTx{Nonce: 2, From: types.ZeroAddress})
tx1 := types.NewTx(&types.LegacyTx{BaseTx: &types.BaseTx{Nonce: 0, From: types.ZeroAddress}})
tx2 := types.NewTx(&types.LegacyTx{BaseTx: &types.BaseTx{Nonce: 1, From: types.ZeroAddress}})
tx3 := types.NewTx(&types.LegacyTx{BaseTx: &types.BaseTx{Nonce: 2, From: types.ZeroAddress}})

computeTxHashes(tx1, tx2, tx3)

Expand Down Expand Up @@ -801,8 +807,8 @@ func Test_recoverFromFieldsInTransactions(t *testing.T) {
},
}

tx1 := types.NewTx(&types.LegacyTx{Nonce: 0, From: addr1})
tx2 := types.NewTx(&types.LegacyTx{Nonce: 1, From: types.ZeroAddress})
tx1 := types.NewTx(&types.LegacyTx{BaseTx: &types.BaseTx{Nonce: 0, From: addr1}})
tx2 := types.NewTx(&types.LegacyTx{BaseTx: &types.BaseTx{Nonce: 1, From: types.ZeroAddress}})

computeTxHashes(tx1, tx2)

Expand Down Expand Up @@ -830,9 +836,9 @@ func Test_recoverFromFieldsInTransactions(t *testing.T) {
},
}

tx1 := types.NewTx(&types.LegacyTx{Nonce: 0, From: types.ZeroAddress})
tx2 := types.NewTx(&types.LegacyTx{Nonce: 1, From: types.ZeroAddress})
tx3 := types.NewTx(&types.LegacyTx{Nonce: 2, From: types.ZeroAddress})
tx1 := types.NewTx(&types.LegacyTx{BaseTx: &types.BaseTx{Nonce: 0, From: types.ZeroAddress}})
tx2 := types.NewTx(&types.LegacyTx{BaseTx: &types.BaseTx{Nonce: 1, From: types.ZeroAddress}})
tx3 := types.NewTx(&types.LegacyTx{BaseTx: &types.BaseTx{Nonce: 2, From: types.ZeroAddress}})

computeTxHashes(tx1, tx2, tx3)

Expand Down Expand Up @@ -864,8 +870,8 @@ func Test_recoverFromFieldsInTransactions(t *testing.T) {
},
}

tx1 := types.NewTx(&types.LegacyTx{Nonce: 0, From: addr1})
tx2 := types.NewTx(&types.LegacyTx{Nonce: 1, From: addr2})
tx1 := types.NewTx(&types.LegacyTx{BaseTx: &types.BaseTx{Nonce: 0, From: addr1}})
tx2 := types.NewTx(&types.LegacyTx{BaseTx: &types.BaseTx{Nonce: 1, From: addr2}})

computeTxHashes(tx1, tx2)

Expand Down Expand Up @@ -901,8 +907,10 @@ func TestBlockchainReadBody(t *testing.T) {
batchWriter := storage.NewBatchWriter(b.db)

tx := types.NewTx(&types.LegacyTx{
Value: big.NewInt(10),
V: big.NewInt(1),
BaseTx: &types.BaseTx{
Value: big.NewInt(10),
V: big.NewInt(1),
},
})

tx.ComputeHash()
Expand Down Expand Up @@ -1603,7 +1611,9 @@ func TestBlockchain_WriteFullBlock(t *testing.T) {
{GasUsed: 200},
}
tx := types.NewTx(&types.LegacyTx{
Value: big.NewInt(1),
BaseTx: &types.BaseTx{
Value: big.NewInt(1),
},
})

tx.ComputeHash()
Expand Down
10 changes: 6 additions & 4 deletions blockchain/storage/leveldb/leveldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ func generateTxs(t *testing.T, startNonce, count int, from types.Address, to *ty

for i := range txs {
tx := types.NewTx(&types.DynamicFeeTx{
Gas: types.StateTransactionGasLimit,
Nonce: uint64(startNonce + i),
To: to,
Value: big.NewInt(2000),
GasFeeCap: big.NewInt(100),
GasTipCap: big.NewInt(10),
BaseTx: &types.BaseTx{
Gas: types.StateTransactionGasLimit,
Nonce: uint64(startNonce + i),
To: to,
Value: big.NewInt(2000),
},
})

input := make([]byte, 1000)
Expand Down
36 changes: 21 additions & 15 deletions blockchain/storage/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,25 +271,29 @@ func testBody(t *testing.T, m PlaceholderStorage) {

addr1 := types.StringToAddress("11")
t0 := types.NewTx(&types.LegacyTx{
Nonce: 0,
To: &addr1,
Value: big.NewInt(1),
Gas: 11,
GasPrice: big.NewInt(11),
Input: []byte{1, 2},
V: big.NewInt(1),
BaseTx: &types.BaseTx{
Nonce: 0,
To: &addr1,
Value: big.NewInt(1),
Gas: 11,
Input: []byte{1, 2},
V: big.NewInt(1),
},
})
t0.ComputeHash()

addr2 := types.StringToAddress("22")
t1 := types.NewTx(&types.LegacyTx{
Nonce: 0,
To: &addr2,
Value: big.NewInt(1),
Gas: 22,
GasPrice: big.NewInt(11),
Input: []byte{4, 5},
V: big.NewInt(2),
BaseTx: &types.BaseTx{
Nonce: 0,
To: &addr2,
Value: big.NewInt(1),
Gas: 22,
Input: []byte{4, 5},
V: big.NewInt(2),
},
})
t1.ComputeHash()

Expand Down Expand Up @@ -339,10 +343,12 @@ func testReceipts(t *testing.T, m PlaceholderStorage) {
body := &types.Body{
Transactions: []*types.Transaction{
types.NewTx(&types.StateTx{
Nonce: 1000,
Gas: 50,
GasPrice: new(big.Int).SetUint64(100),
V: big.NewInt(11),
BaseTx: &types.BaseTx{
Nonce: 1000,
Gas: 50,
V: big.NewInt(11),
},
}),
},
}
Expand Down
10 changes: 6 additions & 4 deletions consensus/polybft/block_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ func TestBlockBuilder_BuildBlockTxOneFailedTxAndOneTakesTooMuchGas(t *testing.T)
}

tx := types.NewTx(&types.LegacyTx{
Value: big.NewInt(amount),
GasPrice: big.NewInt(gasPrice),
Gas: gas,
Nonce: 0,
To: &acc.address,
BaseTx: &types.BaseTx{
Value: big.NewInt(amount),
Gas: gas,
Nonce: 0,
To: &acc.address,
},
})

tx, err = signer.SignTx(tx, acc.privKey)
Expand Down
10 changes: 6 additions & 4 deletions consensus/polybft/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,13 @@ func validateHeaderFields(parent *types.Header, header *types.Header, blockTimeD
// with provided target address and inputData parameter which is ABI encoded byte array.
func createStateTransactionWithData(target types.Address, inputData []byte) *types.Transaction {
tx := types.NewTx(&types.StateTx{
From: contracts.SystemCaller,
To: &target,
Input: inputData,
Gas: types.StateTransactionGasLimit,
GasPrice: big.NewInt(0),
BaseTx: &types.BaseTx{
From: contracts.SystemCaller,
To: &target,
Input: inputData,
Gas: types.StateTransactionGasLimit,
},
})

return tx.ComputeHash()
Expand Down
8 changes: 5 additions & 3 deletions consensus/polybft/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ func TestFSM_verifyCommitEpochTx(t *testing.T) {

// submit tampered commit epoch transaction to the epoch ending block
alteredCommitEpochTx := types.NewTx(&types.StateTx{
To: &contracts.EpochManagerContract,
Input: []byte{},
Gas: 0,
BaseTx: &types.BaseTx{
To: &contracts.EpochManagerContract,
Input: []byte{},
Gas: 0,
},
})
assert.ErrorContains(t, fsm.verifyCommitEpochTx(alteredCommitEpochTx), "invalid commit epoch transaction")

Expand Down
12 changes: 8 additions & 4 deletions crypto/txsigner_eip155_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ func TestEIP155Signer_Sender(t *testing.T) {
}

txn := types.NewTx(&types.LegacyTx{
To: &toAddress,
Value: big.NewInt(1),
GasPrice: big.NewInt(0),
BaseTx: &types.BaseTx{
To: &toAddress,
Value: big.NewInt(1),
},
})

signer := NewEIP155Signer(
Expand Down Expand Up @@ -106,9 +108,11 @@ func TestEIP155Signer_ChainIDMismatch(t *testing.T) {
}

txn := types.NewTx(&types.LegacyTx{
To: &toAddress,
Value: big.NewInt(1),
GasPrice: big.NewInt(0),
BaseTx: &types.BaseTx{
To: &toAddress,
Value: big.NewInt(1),
},
})

signer := NewEIP155Signer(chainIDTop)
Expand Down
6 changes: 4 additions & 2 deletions crypto/txsigner_frontier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ func TestFrontierSigner(t *testing.T) {
assert.NoError(t, err)

txn := types.NewTx(&types.LegacyTx{
To: &toAddress,
Value: big.NewInt(10),
GasPrice: big.NewInt(0),
BaseTx: &types.BaseTx{
To: &toAddress,
Value: big.NewInt(10),
},
})
signedTx, err := signer.SignTx(txn, key)
assert.NoError(t, err)
Expand Down
40 changes: 25 additions & 15 deletions crypto/txsigner_london_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,36 @@ func TestLondonSignerSender(t *testing.T) {
switch tc.txType {
case types.AccessListTxType:
txn = types.NewTx(&types.AccessListTxn{
To: &recipient,
Value: big.NewInt(1),
GasPrice: big.NewInt(5),
ChainID: tc.chainID,
BaseTx: &types.BaseTx{
To: &recipient,
Value: big.NewInt(1),
},
})
case types.LegacyTxType:
txn = types.NewTx(&types.LegacyTx{
To: &recipient,
Value: big.NewInt(1),
GasPrice: big.NewInt(5),
BaseTx: &types.BaseTx{
To: &recipient,
Value: big.NewInt(1),
},
})
case types.StateTxType:
txn = types.NewTx(&types.StateTx{
To: &recipient,
Value: big.NewInt(1),
GasPrice: big.NewInt(5),
BaseTx: &types.BaseTx{
To: &recipient,
Value: big.NewInt(1),
},
})
case types.DynamicFeeTxType:
txn = types.NewTx(&types.DynamicFeeTx{
To: &recipient,
Value: big.NewInt(1),
ChainID: tc.chainID,
BaseTx: &types.BaseTx{
To: &recipient,
Value: big.NewInt(1),
},
})
}

Expand Down Expand Up @@ -135,15 +143,17 @@ func Test_LondonSigner_Sender(t *testing.T) {
{
name: "sender is 0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6",
tx: types.NewTx(&types.DynamicFeeTx{
ChainID: big.NewInt(100),
GasTipCap: ethgo.Gwei(1),
GasFeeCap: ethgo.Gwei(10),
Gas: 21000,
To: &to,
Value: big.NewInt(100000000000000),
V: big.NewInt(0),
R: r,
S: s,
ChainID: big.NewInt(100),
BaseTx: &types.BaseTx{
Gas: 21000,
To: &to,
Value: big.NewInt(100000000000000),
V: big.NewInt(0),
R: r,
S: s,
},
}),
sender: types.StringToAddress("0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6"),
},
Expand Down
14 changes: 8 additions & 6 deletions e2e/framework/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,15 @@ func (t *TestServer) SendRawTx(
}

signedTx, err := t.SignTx(types.NewTx(&types.LegacyTx{
From: tx.From,
GasPrice: tx.GasPrice,
Gas: tx.Gas,
To: tx.To,
Value: tx.Value,
Input: tx.Input,
Nonce: nextNonce,
BaseTx: &types.BaseTx{
Gas: tx.Gas,
To: tx.To,
Value: tx.Value,
Input: tx.Input,
Nonce: nextNonce,
From: tx.From,
},
}), signerKey)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit e5d5a9b

Please sign in to comment.