Skip to content

Commit e6370ed

Browse files
seidroid[bot]masih
andauthored
Backport release/v6.7: Return an empty array from eth_accounts on a keyless node (#4871)
Backport of #4653 to `release/v6.7`. Co-authored-by: Masih H. Derkani <m@derkani.org>
1 parent e0e98fb commit e6370ed

5 files changed

Lines changed: 14 additions & 20 deletions

File tree

‎evmrpc/info.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ func (i *InfoAPI) Accounts(ctx context.Context) (result []common.Address, return
8080
if err != nil {
8181
return []common.Address{}, err
8282
}
83-
for addr := range getAddressPrivKeyMap(kb) {
83+
keys := getAddressPrivKeyMap(kb)
84+
result = make([]common.Address, 0, len(keys))
85+
for addr := range keys {
8486
result = append(result, common.HexToAddress(addr))
8587
}
8688
return result, nil

‎evmrpc/info_test.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package evmrpc_test
22

33
import (
4+
"encoding/json"
45
"errors"
56
"fmt"
67
"math/big"
@@ -63,6 +64,15 @@ func TestAccounts(t *testing.T) {
6364
require.Equal(t, 1, len(accounts))
6465
}
6566

67+
func TestAccountsWithoutKeys(t *testing.T) {
68+
api := evmrpc.NewInfoAPI(nil, nil, nil, nil, t.TempDir(), 1024, evmrpc.ConnectionTypeHTTP, nil, nil)
69+
accounts, err := api.Accounts(t.Context())
70+
require.NoError(t, err)
71+
bz, err := json.Marshal(accounts)
72+
require.NoError(t, err)
73+
require.JSONEq(t, `[]`, string(bz))
74+
}
75+
6676
func TestCoinbase(t *testing.T) {
6777
Ctx = Ctx.WithBlockHeight(1)
6878
resObj := sendRequestGood(t, "coinbase")

‎integration_test/rpc_tests/config/endpoints.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export const Endpoints = {
1414
geth: env('RPC_ETH_GETH', 'http://127.0.0.1:9547'),
1515
fork: env('RPC_ETH_FORK', 'http://127.0.0.1:9546'),
1616
},
17-
accountless: env('RPC_ACCOUNTLESS', 'https://evm-rpc.sei-apis.com'),
1817
} as const;
1918

2019
export const AdminMnemonic = env('SEI_ADMIN_MNEMONIC', '');

‎integration_test/rpc_tests/eth/eth_accounts.spec.ts‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { expect } from 'chai';
2-
import { bothProviders, isReachable, rawSei, rawGeth, rawAccountless, expectJsonRpcError } from '../utils/chainUtils';
2+
import { bothProviders, rawSei, rawGeth, expectJsonRpcError } from '../utils/chainUtils';
33
import { ADDRESS, ADDRESS_LOWER } from '../utils/format';
4-
import { Endpoints } from '../config/endpoints';
54

65
describe('eth_accounts Tests', function () {
76
this.timeout(60 * 1000);
@@ -54,18 +53,6 @@ describe('eth_accounts Tests', function () {
5453
});
5554
});
5655

57-
describe('empty / null handling', () => {
58-
it('a keyless node returns [] (empty array), never null', async function () {
59-
if (!(await isReachable(Endpoints.accountless))) {
60-
this.skip();
61-
}
62-
const body = await rawAccountless<string[]>('eth_accounts', []);
63-
expect(body.error, JSON.stringify(body.error)).to.equal(undefined);
64-
expect(body.result, 'keyless node must encode the empty set as []').to.deep.equal([]);
65-
expect(body.result).to.not.equal(null);
66-
});
67-
});
68-
6956
describe('wrong params / error handling', () => {
7057
it('Sei rejects an extra positional parameter with -32602, identically to geth', async () => {
7158
const [seiBody, gethBody] = await Promise.all([

‎integration_test/rpc_tests/utils/chainUtils.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ export const rawSei = <T = unknown>(method: string, params: unknown) =>
102102
export const rawGeth = <T = unknown>(method: string, params: unknown) =>
103103
rawJsonRpc<T>(Endpoints.eth.geth, method, params);
104104

105-
/** Raw POST to a keyless node (hosted RPC) — used to observe the empty-account case. */
106-
export const rawAccountless = <T = unknown>(method: string, params: unknown) =>
107-
rawJsonRpc<T>(Endpoints.accountless, method, params);
108-
109105
/**
110106
* Resolve a promise expected to throw an ethers RPC error and return the underlying
111107
* JSON-RPC envelope. Unwraps both `e.info.error` (ethers v6 default) and `e.error`

0 commit comments

Comments
 (0)