github.com/ChainSafe/chainbridge-core@v1.4.2/chains/evm/calls/evmtransaction/evm-tx_test.go (about) 1 package evmtransaction 2 3 import ( 4 "math/big" 5 "testing" 6 7 evmgaspricer "github.com/ChainSafe/chainbridge-core/chains/evm/calls/evmgaspricer" 8 mock_evmgaspricer "github.com/ChainSafe/chainbridge-core/chains/evm/calls/evmgaspricer/mock" 9 10 "github.com/ethereum/go-ethereum/core/types" 11 12 "github.com/ChainSafe/chainbridge-core/keystore" 13 14 "github.com/ethereum/go-ethereum/common" 15 16 "github.com/golang/mock/gomock" 17 "github.com/stretchr/testify/suite" 18 ) 19 20 var aliceKp = keystore.TestKeyRing.EthereumKeys[keystore.AliceKey] 21 22 type EVMTxTestSuite struct { 23 suite.Suite 24 client *mock_evmgaspricer.MockLondonGasClient 25 } 26 27 func TestRunTestSuite(t *testing.T) { 28 suite.Run(t, new(EVMTxTestSuite)) 29 } 30 31 func (s *EVMTxTestSuite) SetupSuite() {} 32 func (s *EVMTxTestSuite) TearDownSuite() {} 33 func (s *EVMTxTestSuite) SetupTest() { 34 gomockController := gomock.NewController(s.T()) 35 s.client = mock_evmgaspricer.NewMockLondonGasClient(gomockController) 36 } 37 func (s *EVMTxTestSuite) TearDownTest() {} 38 39 func (s *EVMTxTestSuite) TestNewTransactionWithStaticGasPricer() { 40 s.client.EXPECT().SuggestGasPrice(gomock.Any()).Return(big.NewInt(1000), nil) 41 txFabric := NewTransaction 42 gasPriceClient := evmgaspricer.NewStaticGasPriceDeterminant(s.client, nil) 43 gp, err := gasPriceClient.GasPrice(nil) 44 s.Nil(err) 45 tx, err := txFabric(1, &common.Address{}, big.NewInt(0), 10000, gp, []byte{}) 46 s.Nil(err) 47 rawTx, err := tx.RawWithSignature(aliceKp, big.NewInt(420)) 48 s.Nil(err) 49 txt := types.Transaction{} 50 err = txt.UnmarshalBinary(rawTx) 51 s.Nil(err) 52 s.Equal(types.LegacyTxType, int(txt.Type())) 53 } 54 55 func (s *EVMTxTestSuite) TestNewTransactionWithLondonGasPricer() { 56 s.client.EXPECT().BaseFee().Return(big.NewInt(1000), nil) 57 s.client.EXPECT().SuggestGasTipCap(gomock.Any()).Return(big.NewInt(1000), nil) 58 txFabric := NewTransaction 59 gasPriceClient := evmgaspricer.NewLondonGasPriceClient(s.client, nil) 60 gp, err := gasPriceClient.GasPrice(nil) 61 s.Nil(err) 62 tx, err := txFabric(1, &common.Address{}, big.NewInt(0), 10000, gp, []byte{}) 63 s.Nil(err) 64 rawTx, err := tx.RawWithSignature(aliceKp, big.NewInt(420)) 65 s.Nil(err) 66 txt := types.Transaction{} 67 err = txt.UnmarshalBinary(rawTx) 68 s.Nil(err) 69 s.Equal(types.DynamicFeeTxType, int(txt.Type())) 70 }