Skip to content

Commit

Permalink
other transactions test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dusannosovic-ethernal committed Mar 13, 2024
1 parent da400c3 commit 5eee22f
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 243 deletions.
18 changes: 8 additions & 10 deletions blockchain/storage/leveldb/leveldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ func generateTxs(t *testing.T, startNonce, count int, from types.Address, to *ty
txs := make([]*types.Transaction, count)

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

input := make([]byte, 1000)
_, err := rand.Read(input)
Expand Down
14 changes: 6 additions & 8 deletions blockchain/storage/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,12 @@ func testReceipts(t *testing.T, m PlaceholderStorage) {

body := &types.Body{
Transactions: []*types.Transaction{
types.NewTx(&types.StateTx{
GasPrice: new(big.Int).SetUint64(100),
BaseTx: &types.BaseTx{
Nonce: 1000,
Gas: 50,
V: big.NewInt(11),
},
}),
types.NewTx(types.NewStateTx(
types.WithGasPrice(new(big.Int).SetUint64(100)),
types.WithNonce(1000),
types.WithGas(50),
types.WithSignatureValues(big.NewInt(11), nil, nil),
)),
},
}
receipts := []*types.Receipt{
Expand Down
16 changes: 7 additions & 9 deletions consensus/polybft/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,15 +716,13 @@ func validateHeaderFields(parent *types.Header, header *types.Header, blockTimeD
// createStateTransactionWithData creates a state transaction
// 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{
GasPrice: big.NewInt(0),
BaseTx: &types.BaseTx{
From: contracts.SystemCaller,
To: &target,
Input: inputData,
Gas: types.StateTransactionGasLimit,
},
})
tx := types.NewTx(types.NewStateTx(
types.WithGasPrice(big.NewInt(0)),
types.WithFrom(contracts.SystemCaller),
types.WithTo(&target),
types.WithInput(inputData),
types.WithGas(types.StateTransactionGasLimit),
))

return tx.ComputeHash()
}
13 changes: 6 additions & 7 deletions consensus/polybft/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ func TestFSM_verifyCommitEpochTx(t *testing.T) {
assert.NoError(t, fsm.verifyCommitEpochTx(commitEpochTx))

// submit tampered commit epoch transaction to the epoch ending block
alteredCommitEpochTx := types.NewTx(&types.StateTx{
BaseTx: &types.BaseTx{
To: &contracts.EpochManagerContract,
Input: []byte{},
Gas: 0,
},
})
alteredCommitEpochTx := types.NewTx(types.NewStateTx(
types.WithTo(&contracts.EpochManagerContract),
types.WithInput([]byte{}),
types.WithGas(0),
))

assert.ErrorContains(t, fsm.verifyCommitEpochTx(alteredCommitEpochTx), "invalid commit epoch transaction")

// submit validators commit epoch transaction to the non-epoch ending block
Expand Down
60 changes: 25 additions & 35 deletions crypto/txsigner_london_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,30 @@ func TestLondonSignerSender(t *testing.T) {

switch tc.txType {
case types.AccessListTxType:
txn = types.NewTx(&types.AccessListTxn{
GasPrice: big.NewInt(5),
ChainID: tc.chainID,
BaseTx: &types.BaseTx{
To: &recipient,
Value: big.NewInt(1),
},
})
txn = types.NewTx(types.NewAccessListTx(
types.WithGasPrice(big.NewInt(5)),
types.WithChainID(tc.chainID),
types.WithTo(&recipient),
types.WithValue(big.NewInt(1)),
))
case types.LegacyTxType:
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),
BaseTx: &types.BaseTx{
To: &recipient,
Value: big.NewInt(1),
},
})
txn = types.NewTx(types.NewStateTx(
types.WithGasPrice(big.NewInt(5)),
types.WithTo(&recipient),
types.WithValue(big.NewInt(1)),
))
case types.DynamicFeeTxType:
txn = types.NewTx(&types.DynamicFeeTx{
ChainID: tc.chainID,
BaseTx: &types.BaseTx{
To: &recipient,
Value: big.NewInt(1),
},
})
txn = types.NewTx(types.NewDynamicFeeTx(
types.WithChainID(tc.chainID),
types.WithTo(&recipient),
types.WithValue(big.NewInt(1)),
))
}

chainID := tc.chainID.Uint64()
Expand Down Expand Up @@ -140,19 +134,15 @@ 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),
BaseTx: &types.BaseTx{
Gas: 21000,
To: &to,
Value: big.NewInt(100000000000000),
V: big.NewInt(0),
R: r,
S: s,
},
}),
tx: types.NewTx(types.NewDynamicFeeTx(
types.WithChainID(big.NewInt(100)),
types.WithGasTipCap(ethgo.Gwei(1)),
types.WithGasFeeCap(ethgo.Gwei(10)),
types.WithGas(21000),
types.WithTo(&to),
types.WithValue(big.NewInt(100000000000000)),
types.WithSignatureValues(big.NewInt(0), r, s),
)),
sender: types.StringToAddress("0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6"),
},
}
Expand Down
37 changes: 16 additions & 21 deletions e2e/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,12 @@ func generateTx(params generateTxReqParams) *types.Transaction {
))
unsignedTx.SetGasPrice(params.gasPrice)
} else {
unsignedTx = types.NewTx(&types.DynamicFeeTx{
ChainID: new(big.Int).SetUint64(defaultChainID),
BaseTx: &types.BaseTx{
Nonce: params.nonce,
To: &params.toAddress,
Gas: 1000000,
Value: params.value,
},
})
unsignedTx = types.NewTx(types.NewDynamicFeeTx(
types.WithNonce(params.nonce),
types.WithTo(&params.toAddress),
types.WithGas(1000000),
types.WithValue(params.value),
))
unsignedTx.SetGasFeeCap(params.gasFeeCap)
unsignedTx.SetGasTipCap(params.gasTipCap)
}
Expand Down Expand Up @@ -260,18 +257,16 @@ func TestTxPool_RecoverableError(t *testing.T) {
types.WithValue(oneEth),
types.WithSignatureValues(big.NewInt(27), nil, nil),
)),
types.NewTx(&types.DynamicFeeTx{
ChainID: new(big.Int).SetUint64(defaultChainID),
GasFeeCap: big.NewInt(framework.DefaultGasPrice),
GasTipCap: big.NewInt(1000000000),
BaseTx: &types.BaseTx{
Nonce: 2,
Gas: 22000,
To: &receiverAddress,
Value: oneEth,
V: big.NewInt(27),
},
}),
types.NewTx(types.NewDynamicFeeTx(
types.WithChainID(new(big.Int).SetUint64(defaultChainID)),
types.WithGasFeeCap(big.NewInt(framework.DefaultGasPrice)),
types.WithGasTipCap(big.NewInt(1000000000)),
types.WithNonce(2),
types.WithGas(22000),
types.WithTo(&receiverAddress),
types.WithValue(oneEth),
types.WithSignatureValues(big.NewInt(27), nil, nil),
)),
}

server := framework.NewTestServers(t, 1, func(config *framework.TestServerConfig) {
Expand Down
14 changes: 6 additions & 8 deletions gasprice/feehistory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,12 @@ func TestGasHelper_FeeHistory(t *testing.T) {
b.Header.Miner = sender.Bytes()

for i := 0; i < 3; i++ {
tx := types.NewTx(&types.DynamicFeeTx{
GasTipCap: ethgo.Gwei(uint64(200)),
GasFeeCap: ethgo.Gwei(uint64(200 + 200)),
BaseTx: &types.BaseTx{
Value: ethgo.Ether(1),
To: &types.ZeroAddress,
},
})
tx := types.NewTx(types.NewDynamicFeeTx(
types.WithGasTipCap(ethgo.Gwei(200)),
types.WithGasFeeCap(ethgo.Gwei(200+200)),
types.WithValue(ethgo.Ether(1)),
types.WithTo(&types.ZeroAddress),
))

tx, err := signer.SignTx(tx, senderKey)
require.NoError(t, err)
Expand Down
36 changes: 16 additions & 20 deletions gasprice/gasprice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,14 @@ func TestGasHelper_MaxPriorityFeePerGas(t *testing.T) {
b.Header.Miner = sender.Bytes()

for i := 0; i < 3; i++ {
tx := types.NewTx(&types.DynamicFeeTx{
GasTipCap: ethgo.Gwei(uint64(rand.Intn(200))),
GasFeeCap: ethgo.Gwei(uint64(rand.Intn(200) + 200)),
ChainID: big.NewInt(backend.Config().ChainID),
BaseTx: &types.BaseTx{
From: sender,
Value: ethgo.Ether(1),
To: &types.ZeroAddress,
},
})
tx := types.NewTx(types.NewDynamicFeeTx(
types.WithGasTipCap(ethgo.Gwei(uint64(rand.Intn(200)))),
types.WithGasFeeCap(ethgo.Gwei(uint64(rand.Intn(200)+200))),
types.WithChainID(big.NewInt(backend.Config().ChainID)),
types.WithFrom(sender),
types.WithValue(ethgo.Ether(1)),
types.WithTo(&types.ZeroAddress),
))

tx, err := signer.SignTx(tx, senderKey)
require.NoError(t, err)
Expand Down Expand Up @@ -221,16 +219,14 @@ func createTestTxs(t *testing.T, backend *backendMock, numOfTxsPerBlock, txCap i
for i := 0; i < numOfTxsPerBlock; i++ {
senderKey, sender := tests.GenerateKeyAndAddr(t)

tx := types.NewTx(&types.DynamicFeeTx{
GasTipCap: ethgo.Gwei(uint64(rand.Intn(txCap))),
GasFeeCap: ethgo.Gwei(uint64(rand.Intn(txCap) + txCap)),
ChainID: big.NewInt(backend.Config().ChainID),
BaseTx: &types.BaseTx{
From: sender,
Value: ethgo.Ether(1),
To: &types.ZeroAddress,
},
})
tx := types.NewTx(types.NewDynamicFeeTx(
types.WithGasTipCap(ethgo.Gwei(uint64(rand.Intn(txCap)))),
types.WithGasFeeCap(ethgo.Gwei(uint64(rand.Intn(txCap)+txCap))),
types.WithChainID(big.NewInt(backend.Config().ChainID)),
types.WithFrom(sender),
types.WithValue(ethgo.Ether(1)),
types.WithTo(&types.ZeroAddress),
))

tx, err := signer.SignTx(tx, senderKey)
require.NoError(t, err)
Expand Down
22 changes: 10 additions & 12 deletions jsonrpc/debug_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,18 +605,16 @@ func TestTraceCall(t *testing.T) {
Nonce: &nonce,
Type: toArgUint64Ptr(uint64(types.DynamicFeeTxType)),
}
decodedTx = types.NewTx(&types.DynamicFeeTx{
GasTipCap: new(big.Int).SetBytes([]byte(gasTipCap)),
GasFeeCap: new(big.Int).SetBytes([]byte(gasFeeCap)),
BaseTx: &types.BaseTx{
Nonce: uint64(nonce),
Gas: uint64(gas),
To: &to,
Value: new(big.Int).SetBytes([]byte(value)),
Input: data,
From: from,
},
})
decodedTx = types.NewTx(types.NewDynamicFeeTx(
types.WithGasTipCap(new(big.Int).SetBytes([]byte(gasTipCap))),
types.WithGasFeeCap(new(big.Int).SetBytes([]byte(gasFeeCap))),
types.WithNonce(uint64(nonce)),
types.WithGas(uint64(gas)),
types.WithTo(&to),
types.WithValue(new(big.Int).SetBytes([]byte(value))),
types.WithInput(data),
types.WithFrom(from),
))
)

decodedTx.ComputeHash()
Expand Down
44 changes: 20 additions & 24 deletions jsonrpc/eth_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,16 @@ func TestEth_DecodeTxn(t *testing.T) {
Nonce: toArgUint64Ptr(0),
Type: toArgUint64Ptr(uint64(types.DynamicFeeTxType)),
},
res: types.NewTx(&types.DynamicFeeTx{
GasTipCap: big.NewInt(10000),
GasFeeCap: big.NewInt(10000),
BaseTx: &types.BaseTx{
From: addr1,
To: &addr2,
Gas: 21000,
Value: oneEther,
Input: []byte{},
Nonce: 0,
},
}),
res: types.NewTx(types.NewDynamicFeeTx(
types.WithGasTipCap(big.NewInt(10000)),
types.WithGasFeeCap(big.NewInt(10000)),
types.WithFrom(addr1),
types.WithTo(&addr2),
types.WithGas(21000),
types.WithValue(oneEther),
types.WithInput([]byte{}),
types.WithNonce(0),
)),
err: nil,
},
{
Expand Down Expand Up @@ -271,18 +269,16 @@ func TestEth_TxnType(t *testing.T) {
Type: toArgUint64Ptr(uint64(types.DynamicFeeTxType)),
}

expectedRes := types.NewTx(&types.DynamicFeeTx{
GasTipCap: big.NewInt(10000),
GasFeeCap: big.NewInt(10000),
BaseTx: &types.BaseTx{
From: addr1,
To: &addr2,
Gas: 21000,
Value: oneEther,
Input: []byte{},
Nonce: 0,
},
})
expectedRes := types.NewTx(types.NewDynamicFeeTx(
types.WithGasTipCap(big.NewInt(10000)),
types.WithGasFeeCap(big.NewInt(10000)),
types.WithFrom(addr1),
types.WithTo(&addr2),
types.WithGas(21000),
types.WithValue(oneEther),
types.WithInput([]byte{}),
types.WithNonce(0),
))
res, err := DecodeTxn(args, 1, store, false)

expectedRes.ComputeHash()
Expand Down
Loading

0 comments on commit 5eee22f

Please sign in to comment.