Skip to content

Commit f2497bb

Browse files
committed
test: check extra API
1 parent 1b29d4a commit f2497bb

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

internal/ethapi/api_extra_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,86 @@
44
package ethapi
55

66
import (
7+
"context"
78
"errors"
89
"math/big"
910
"testing"
1011

1112
"github.com/ava-labs/libevm/common"
13+
"github.com/ava-labs/libevm/common/hexutil"
1214
"github.com/ava-labs/libevm/core/types"
15+
ethparams "github.com/ava-labs/libevm/params"
1316
"github.com/stretchr/testify/assert"
17+
"github.com/stretchr/testify/require"
1418
"go.uber.org/mock/gomock"
1519

20+
"github.com/ava-labs/coreth/consensus/dummy"
21+
"github.com/ava-labs/coreth/core"
22+
"github.com/ava-labs/coreth/params"
1623
"github.com/ava-labs/coreth/rpc"
1724
)
1825

26+
func TestBlockchainAPI_GetChainConfig(t *testing.T) {
27+
t.Parallel()
28+
29+
ctrl := gomock.NewController(t)
30+
defer ctrl.Finish()
31+
32+
wantConfig := &params.ChainConfig{
33+
ChainID: big.NewInt(43114),
34+
}
35+
backend := NewMockBackend(ctrl)
36+
backend.EXPECT().ChainConfig().Return(wantConfig)
37+
38+
api := NewBlockChainAPI(backend)
39+
40+
gotConfig := api.GetChainConfig(context.Background())
41+
assert.Equal(t, wantConfig, gotConfig)
42+
}
43+
44+
// Copy one test case from TestCall
45+
func TestBlockchainAPI_CallDetailed(t *testing.T) {
46+
t.Parallel()
47+
// Initialize test accounts
48+
var (
49+
accounts = newAccounts(2)
50+
genesis = &core.Genesis{
51+
Config: params.TestChainConfig,
52+
Alloc: types.GenesisAlloc{
53+
accounts[0].addr: {Balance: big.NewInt(params.Ether)},
54+
accounts[1].addr: {Balance: big.NewInt(params.Ether)},
55+
},
56+
}
57+
genBlocks = 10
58+
signer = types.HomesteadSigner{}
59+
blockNumber = rpc.LatestBlockNumber
60+
)
61+
api := NewBlockChainAPI(newTestBackend(t, genBlocks, genesis, dummy.NewCoinbaseFaker(), func(i int, b *core.BlockGen) {
62+
// Transfer from account[0] to account[1]
63+
// value: 1000 wei
64+
// fee: 0 wei
65+
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), Gas: ethparams.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key)
66+
b.AddTx(tx)
67+
}))
68+
69+
result, err := api.CallDetailed(
70+
context.Background(),
71+
TransactionArgs{
72+
From: &accounts[0].addr,
73+
To: &accounts[1].addr,
74+
Value: (*hexutil.Big)(big.NewInt(1000)),
75+
},
76+
rpc.BlockNumberOrHash{BlockNumber: &blockNumber},
77+
nil,
78+
)
79+
require.NoError(t, err)
80+
require.NotNil(t, result)
81+
require.Equal(t, 0, result.ErrCode)
82+
require.Nil(t, result.ReturnData)
83+
require.Equal(t, ethparams.TxGas, result.UsedGas)
84+
require.Empty(t, result.Err)
85+
}
86+
1987
func TestBlockChainAPI_stateQueryBlockNumberAllowed(t *testing.T) {
2088
t.Parallel()
2189

precompile/contracts/warp/predicate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func createSnowCtx(tb testing.TB, validatorRanges []validatorRange) *snow.Contex
193193
GetSubnetIDF: func(context.Context, ids.ID) (ids.ID, error) {
194194
return sourceSubnetID, nil
195195
},
196-
GetValidatorSetF: func(_ context.Context, _ uint64, _ ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
196+
GetValidatorSetF: func(context.Context, uint64, ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
197197
return getValidatorsOutput, nil
198198
},
199199
}
@@ -669,10 +669,10 @@ func makeWarpPredicateTests(tb testing.TB) map[string]precompiletest.PredicateTe
669669

670670
snowCtx := snowtest.Context(tb, snowtest.CChainID)
671671
state := &validatorstest.State{
672-
GetSubnetIDF: func(_ context.Context, _ ids.ID) (ids.ID, error) {
672+
GetSubnetIDF: func(context.Context, ids.ID) (ids.ID, error) {
673673
return sourceSubnetID, nil
674674
},
675-
GetValidatorSetF: func(_ context.Context, _ uint64, _ ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
675+
GetValidatorSetF: func(context.Context, uint64, ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
676676
return getValidatorsOutput, nil
677677
},
678678
}

0 commit comments

Comments
 (0)