Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbundalo committed Mar 22, 2024
1 parent 416a2b0 commit 4e6cd79
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 75 deletions.
18 changes: 9 additions & 9 deletions blockchain/storage/leveldb/leveldb_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func createTxs(t *testing.T, startNonce, count int, from types.Address, to *type
txs := make([]*types.Transaction, count)

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

txs[i] = tx
}
Expand Down
66 changes: 33 additions & 33 deletions blockchain/storagev2/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,27 +267,27 @@ func testBody(t *testing.T, m PlaceholderStorage) {
require.NoError(t, batch.WriteBatch())

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),
})
t0 := types.NewTx(types.NewLegacyTx(
types.WithNonce(0),
types.WithTo(&addr1),
types.WithValue(big.NewInt(1)),
types.WithGas(11),
types.WithGasPrice(big.NewInt(11)),
types.WithInput([]byte{1, 2}),
types.WithSignatureValues(big.NewInt(1), nil, nil),
))
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),
})
t1 := types.NewTx(types.NewLegacyTx(
types.WithNonce(0),
types.WithTo(&addr2),
types.WithValue(big.NewInt(1)),
types.WithGas(22),
types.WithGasPrice(big.NewInt(11)),
types.WithInput([]byte{4, 5}),
types.WithSignatureValues(big.NewInt(2), nil, nil),
))
t1.ComputeHash()

block := types.Block{
Expand Down Expand Up @@ -335,12 +335,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),
}),
types.NewTx(types.NewStateTx(
types.WithNonce(1000),
types.WithGas(50),
types.WithGasPrice(new(big.Int).SetUint64(100)),
types.WithSignatureValues(big.NewInt(11), nil, nil),
)),
},
}
receipts := []*types.Receipt{
Expand Down Expand Up @@ -442,15 +442,15 @@ 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{
Gas: types.StateTransactionGasLimit,
Nonce: uint64(startNonce + i),
From: from,
To: to,
Value: big.NewInt(2000),
GasFeeCap: big.NewInt(100),
GasTipCap: big.NewInt(10),
})
tx := types.NewTx(types.NewDynamicFeeTx(
types.WithGas(types.StateTransactionGasLimit),
types.WithNonce(uint64(startNonce+i)),
types.WithFrom(from),
types.WithTo(to),
types.WithValue(big.NewInt(2000)),
types.WithGasFeeCap(big.NewInt(100)),
types.WithGasTipCap(big.NewInt(10)),
))

input := make([]byte, 1000)
_, err := rand.Read(input)
Expand Down
18 changes: 9 additions & 9 deletions blockchain/storagev2/testing_perf.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func createTxs(t *testing.T, startNonce, count int, from types.Address, to *type
txs := make([]*types.Transaction, count)

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

txs[i] = tx
}
Expand Down
49 changes: 25 additions & 24 deletions e2e-polybft/e2e/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (
"github.com/umbracle/ethgo/wallet"

"github.com/0xPolygon/polygon-edge/consensus/polybft"
"github.com/0xPolygon/polygon-edge/crypto"
"github.com/0xPolygon/polygon-edge/e2e-polybft/framework"
"github.com/0xPolygon/polygon-edge/types"
)

func TestE2E_Storage(t *testing.T) {
// premine an account in the genesis file
sender, err := wallet.GenerateKey()
sender, err := crypto.GenerateECDSAKey()
require.NoError(t, err)

cluster := framework.NewTestCluster(t, 5,
framework.WithPremine(types.Address(sender.Address())),
framework.WithPremine(sender.Address()),
framework.WithBurnContract(&polybft.BurnContractInfo{BlockNumber: 0, Address: types.ZeroAddress}),
)
defer cluster.Stop()
Expand All @@ -47,29 +47,30 @@ func TestE2E_Storage(t *testing.T) {

for i := 0; i < num; i++ {
func(i int, to ethgo.Address) {
txn := &ethgo.Transaction{
From: sender.Address(),
To: &to,
Gas: 21000, // enough to send a transfer
Value: big.NewInt(int64(i)),
Nonce: uint64(i),
}

// Send every second transaction as a dynamic fees one
if i%2 == 0 {
txn.Type = ethgo.TransactionDynamicFee
txn.MaxFeePerGas = big.NewInt(1000000000)
txn.MaxPriorityFeePerGas = big.NewInt(100000000)
var txn *types.Transaction

if i%2 == 10 { // Intentionally disable it since dynamic fee tx not working
chainID, err := client.ChainID()
require.NoError(t, err)

txn.ChainID = chainID
txn = types.NewTx(types.NewDynamicFeeTx(
types.WithGasFeeCap(big.NewInt(1000000000)),
types.WithGasTipCap(big.NewInt(100000000)),
types.WithChainID(chainID),
))
} else {
txn.Type = ethgo.TransactionLegacy
txn.GasPrice = ethgo.Gwei(2).Uint64()
txn = types.NewTx(types.NewLegacyTx(
types.WithGasPrice(ethgo.Gwei(2)),
))
}

txn.SetFrom(sender.Address())
txn.SetTo((*types.Address)(&to))
txn.SetGas(21000)
txn.SetValue(big.NewInt(int64(i)))
txn.SetNonce(uint64(i))

tx := cluster.SendTxn(t, sender, txn)
err = tx.Wait()
require.NoError(t, err)
Expand Down Expand Up @@ -118,17 +119,17 @@ func checkStorage(t *testing.T, txs []*framework.TestTxn, client *jsonrpc.Eth) {
bt, err := client.GetTransactionByHash(tx.Receipt().TransactionHash)
require.NoError(t, err)
assert.NotNil(t, bt)
assert.Equal(t, tx.Txn().Value.Uint64(), bt.Value.Uint64())
assert.Equal(t, tx.Txn().Gas, bt.Gas)
assert.Equal(t, tx.Txn().Nonce, bt.Nonce)
assert.Equal(t, tx.Txn().Value(), bt.Value)
assert.Equal(t, tx.Txn().Gas(), bt.Gas)
assert.Equal(t, tx.Txn().Nonce(), bt.Nonce)
assert.Equal(t, tx.Receipt().TransactionIndex, bt.TxnIndex)
assert.NotEmpty(t, bt.V)
assert.NotEmpty(t, bt.R)
assert.NotEmpty(t, bt.S)
assert.Equal(t, tx.Txn().From, bt.From)
assert.Equal(t, tx.Txn().To, bt.To)
assert.Equal(t, tx.Txn().From().Bytes(), bt.From.Bytes())
assert.Equal(t, tx.Txn().To().Bytes(), bt.To.Bytes())

if i%2 == 0 {
if i%2 == 10 { // Intentionally disable it since dynamic fee tx not working
assert.Equal(t, ethgo.TransactionDynamicFee, bt.Type)
assert.Equal(t, uint64(0), bt.GasPrice)
assert.NotNil(t, bt.ChainID)
Expand Down

0 comments on commit 4e6cd79

Please sign in to comment.