Skip to content

Commit

Permalink
Add eth_accounts endpoint (#93)
Browse files Browse the repository at this point in the history
* add eth_accounts endpoint

* move eth_accounts to test web3 rpc handler

* add eth_accounts test
  • Loading branch information
K-Ho authored Apr 23, 2020
1 parent 5aa6cdd commit 16fad0c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/rollup-full-node/src/app/test-web3-rpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export class TestWeb3Handler extends DefaultWeb3Handler {
case Web3RpcMethods.revert:
this.assertParameters(params, 1)
return this.revert(params[0])
case Web3RpcMethods.accounts:
this.assertParameters(params, 0)
return this.accounts()
default:
return super.handleRequest(method, params)
}
Expand Down Expand Up @@ -147,4 +150,14 @@ export class TestWeb3Handler extends DefaultWeb3Handler {
this.timestampIncreaseSeconds = this.timestampIncreaseSnapshots[snapShotId]
return response
}

public async accounts(): Promise<string> {
log.debug('Getting accounts')
const response = await this.context.provider.send(
Web3RpcMethods.accounts,
[]
)
log.debug(`Received accounts [${response}].`)
return response
}
}
1 change: 1 addition & 0 deletions packages/rollup-full-node/src/types/web3-rpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export enum Web3RpcMethods {
chainId = 'eth_chainId',

// Test methods:
accounts = 'eth_accounts',
snapshot = 'evm_snapshot',
revert = 'evm_revert',
mine = 'evm_mine',
Expand Down
25 changes: 25 additions & 0 deletions packages/rollup-full-node/test/app/test-web-rpc-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,29 @@ describe('TestHandler', () => {
res.should.equal(storageValue)
})
})

describe('the accounts endpoint', () => {
let testRpcServer
let httpProvider

beforeEach(async () => {
testRpcServer = new FullnodeRpcServer(testHandler, host, port)
testRpcServer.listen()
httpProvider = new ethers.providers.JsonRpcProvider(baseUrl)
})

afterEach(async () => {
await testRpcServer.close()
})

it('should get accounts', async () => {
const response = await httpProvider.send('eth_accounts', [])
const addresses = getWallets(httpProvider).map((wallet) =>
wallet['signingKey']['address'].toLowerCase()
)
response
.map((address) => address.toLowerCase())
.should.have.members(addresses)
})
})
})

0 comments on commit 16fad0c

Please sign in to comment.