Skip to content

Commit edfdd00

Browse files
committed
other(tests): Add test for legacy evm transaction
1 parent 9519c57 commit edfdd00

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

tests/rpc/rpc_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func call(t *testing.T, method string, params interface{}) *Response {
6363
}
6464

6565
//nolint:unparam
66-
func submitTransaction(ctx context.Context, t *testing.T, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *types.Receipt {
66+
func submitTransaction(ctx context.Context, t *testing.T, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, legacy bool) *types.Receipt {
6767
ec := localClient(t, false)
6868
chainID, err := ec.ChainID(context.Background())
6969
require.NoError(t, err)
@@ -81,6 +81,9 @@ func submitTransaction(ctx context.Context, t *testing.T, to common.Address, amo
8181
data,
8282
)
8383
signer := types.LatestSignerForChainID(chainID)
84+
if legacy {
85+
signer = types.LatestSignerForChainID(nil)
86+
}
8487
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), tests.TestKey1.Private)
8588
require.Nil(t, err, "sign tx")
8689

@@ -100,7 +103,7 @@ func submitTransaction(ctx context.Context, t *testing.T, to common.Address, amo
100103
func submitTestTransaction(ctx context.Context, t *testing.T) *types.Receipt {
101104
data := common.FromHex("0x7f7465737432000000000000000000000000000000000000000000000000000000600057")
102105
to := common.BytesToAddress(common.FromHex("0x1122334455667788990011223344556677889900"))
103-
return submitTransaction(ctx, t, to, big.NewInt(1), GasLimit, GasPrice, data)
106+
return submitTransaction(ctx, t, to, big.NewInt(1), GasLimit, GasPrice, data, false)
104107
}
105108

106109
func TestEth_GetBalance(t *testing.T) {
@@ -209,7 +212,15 @@ func TestEth_SendRawTransaction(t *testing.T) {
209212
ctx, cancel := context.WithTimeout(context.Background(), OasisBlockTimeout)
210213
defer cancel()
211214

212-
receipt := submitTransaction(ctx, t, common.Address{1}, big.NewInt(1), GasLimit, GasPrice, nil)
215+
receipt := submitTransaction(ctx, t, common.Address{1}, big.NewInt(1), GasLimit, GasPrice, nil, false)
216+
require.EqualValues(t, 1, receipt.Status)
217+
}
218+
219+
func TestEth_SendRawLegacyTransaction(t *testing.T) {
220+
ctx, cancel := context.WithTimeout(context.Background(), OasisBlockTimeout)
221+
defer cancel()
222+
223+
receipt := submitTransaction(ctx, t, common.Address{1}, big.NewInt(1), GasLimit, GasPrice, nil, true)
213224
require.EqualValues(t, 1, receipt.Status)
214225
}
215226

@@ -328,7 +339,7 @@ func TestEth_GetTransactionByHash(t *testing.T) {
328339
input := "0x7f7465737432000000000000000000000000000000000000000000000000000000600057"
329340
data := common.FromHex(input)
330341
to := common.BytesToAddress(common.FromHex("0x1122334455667788990011223344556677889900"))
331-
receipt := submitTransaction(ctx, t, to, big.NewInt(1), GasLimit, GasPrice, data)
342+
receipt := submitTransaction(ctx, t, to, big.NewInt(1), GasLimit, GasPrice, data, false)
332343
require.EqualValues(t, 1, receipt.Status)
333344
require.NotNil(t, receipt)
334345

@@ -361,7 +372,7 @@ func TestEth_GetTransactionByBlockAndIndex(t *testing.T) {
361372
input := "0x7f7465737432000000000000000000000000000000000000000000000000000000600057"
362373
data := common.FromHex(input)
363374
to := common.BytesToAddress(common.FromHex("0x1122334455667788990011223344556677889900"))
364-
receipt := submitTransaction(ctx, t, to, big.NewInt(1), GasLimit, GasPrice, data)
375+
receipt := submitTransaction(ctx, t, to, big.NewInt(1), GasLimit, GasPrice, data, false)
365376
require.EqualValues(t, 1, receipt.Status)
366377
require.NotNil(t, receipt)
367378

0 commit comments

Comments
 (0)