Skip to content

Commit

Permalink
legacy transaction test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dusannosovic-ethernal committed Mar 13, 2024
1 parent 466a070 commit da400c3
Show file tree
Hide file tree
Showing 24 changed files with 374 additions and 360 deletions.
67 changes: 25 additions & 42 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,13 +590,8 @@ func TestBlockchainWriteBody(t *testing.T) {
t.Run("should succeed if tx has from field", func(t *testing.T) {
t.Parallel()

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

block := &types.Block{
Header: &types.Header{},
Expand Down Expand Up @@ -624,12 +619,8 @@ func TestBlockchainWriteBody(t *testing.T) {
t.Run("should return error if tx doesn't have from and recovering address fails", func(t *testing.T) {
t.Parallel()

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

block := &types.Block{
Header: &types.Header{},
Expand Down Expand Up @@ -658,12 +649,8 @@ func TestBlockchainWriteBody(t *testing.T) {
t.Run("should recover from address and store to storage", func(t *testing.T) {
t.Parallel()

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

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

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}})
tx1 := types.NewTx(types.NewLegacyTx(types.WithNonce(0), types.WithFrom(addr1)))
tx2 := types.NewTx(types.NewLegacyTx(types.WithNonce(1), types.WithFrom(types.ZeroAddress)))

computeTxHashes(tx1, tx2)

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

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}})
tx1 := types.NewTx(types.NewLegacyTx(types.WithNonce(0), types.WithFrom(types.ZeroAddress)))
tx2 := types.NewTx(types.NewLegacyTx(types.WithNonce(1), types.WithFrom(types.ZeroAddress)))
tx3 := types.NewTx(types.NewLegacyTx(types.WithNonce(2), types.WithFrom(types.ZeroAddress)))

computeTxHashes(tx1, tx2, tx3)

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

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}})
tx1 := types.NewTx(types.NewLegacyTx(types.WithNonce(0), types.WithFrom(addr1)))
tx2 := types.NewTx(types.NewLegacyTx(types.WithNonce(1), types.WithFrom(types.ZeroAddress)))

computeTxHashes(tx1, tx2)

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

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}})
tx1 := types.NewTx(types.NewLegacyTx(types.WithNonce(0), types.WithFrom(types.ZeroAddress)))
tx2 := types.NewTx(types.NewLegacyTx(types.WithNonce(1), types.WithFrom(types.ZeroAddress)))
tx3 := types.NewTx(types.NewLegacyTx(types.WithNonce(2), types.WithFrom(types.ZeroAddress)))

computeTxHashes(tx1, tx2, tx3)

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

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

computeTxHashes(tx1, tx2)

Expand Down Expand Up @@ -906,12 +893,10 @@ func TestBlockchainReadBody(t *testing.T) {

batchWriter := storage.NewBatchWriter(b.db)

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

tx.ComputeHash()

Expand Down Expand Up @@ -1610,11 +1595,9 @@ func TestBlockchain_WriteFullBlock(t *testing.T) {
{GasUsed: 100},
{GasUsed: 200},
}
tx := types.NewTx(&types.LegacyTx{
BaseTx: &types.BaseTx{
Value: big.NewInt(1),
},
})
tx := types.NewTx(types.NewLegacyTx(
types.WithValue(big.NewInt(1)),
))

tx.ComputeHash()
header.ComputeHash()
Expand Down
40 changes: 18 additions & 22 deletions blockchain/storage/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,31 +270,27 @@ func testBody(t *testing.T, m PlaceholderStorage) {
require.NoError(t, batch.WriteBatch())

addr1 := types.StringToAddress("11")
t0 := types.NewTx(&types.LegacyTx{
GasPrice: big.NewInt(11),
BaseTx: &types.BaseTx{
Nonce: 0,
To: &addr1,
Value: big.NewInt(1),
Gas: 11,
Input: []byte{1, 2},
V: big.NewInt(1),
},
})
t0 := types.NewTx(types.NewLegacyTx(
types.WithGasPrice(big.NewInt(11)),
types.WithNonce(0),
types.WithTo(&addr1),
types.WithValue(big.NewInt(1)),
types.WithGas(11),
types.WithInput([]byte{1, 2}),
types.WithSignatureValues(big.NewInt(1), nil, nil),
))
t0.ComputeHash()

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

block := types.Block{
Expand Down
16 changes: 7 additions & 9 deletions consensus/polybft/block_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,13 @@ func TestBlockBuilder_BuildBlockTxOneFailedTxAndOneTakesTooMuchGas(t *testing.T)
gas = blockGasLimit - 1
}

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

tx, err = signer.SignTx(tx, acc.privKey)
require.NoError(t, err)
Expand Down
24 changes: 10 additions & 14 deletions crypto/txsigner_eip155_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ func TestEIP155Signer_Sender(t *testing.T) {
t.Fatalf("Unable to generate key")
}

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

signer := NewEIP155Signer(
testCase.chainID.Uint64(),
Expand Down Expand Up @@ -107,13 +105,11 @@ func TestEIP155Signer_ChainIDMismatch(t *testing.T) {
t.Fatalf("Unable to generate key")
}

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

signer := NewEIP155Signer(chainIDTop)

Expand Down
13 changes: 6 additions & 7 deletions crypto/txsigner_frontier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ func TestFrontierSigner(t *testing.T) {
key, err := GenerateECDSAKey()
assert.NoError(t, err)

txn := types.NewTx(&types.LegacyTx{
GasPrice: big.NewInt(0),
BaseTx: &types.BaseTx{
To: &toAddress,
Value: big.NewInt(10),
},
})
txn := types.NewTx(types.NewLegacyTx(
types.WithGasPrice(big.NewInt(0)),
types.WithTo(&toAddress),
types.WithValue(big.NewInt(10)),
))

signedTx, err := signer.SignTx(txn, key)
assert.NoError(t, err)

Expand Down
12 changes: 5 additions & 7 deletions crypto/txsigner_london_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ func TestLondonSignerSender(t *testing.T) {
},
})
case types.LegacyTxType:
txn = types.NewTx(&types.LegacyTx{
GasPrice: big.NewInt(5),
BaseTx: &types.BaseTx{
To: &recipient,
Value: big.NewInt(1),
},
})
txn = types.NewTx(types.NewLegacyTx(
types.WithGasPrice(big.NewInt(5)),
types.WithTo(&recipient),
types.WithValue(big.NewInt(1)),
))
case types.StateTxType:
txn = types.NewTx(&types.StateTx{
GasPrice: big.NewInt(5),
Expand Down
20 changes: 9 additions & 11 deletions e2e/framework/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,17 +520,15 @@ func (t *TestServer) SendRawTx(
return nil, err
}

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

0 comments on commit da400c3

Please sign in to comment.