Skip to content

Commit

Permalink
Save Wed Jun 14 11:10:20 AM -03 2023
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Arregui committed Jun 14, 2023
1 parent be3ea81 commit 232711a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/methods/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export namespace eth {
export const eth_getLogs = new Method({
callName: 'eth_getLogs',
params: 1,
inputFormatter: [utils.toHex],
inputFormatter: [utils.toArray],
outputFormatter: utils.toArray
})

Expand Down
48 changes: 30 additions & 18 deletions test/helpers/NodeConnectionFactory.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
import ganache from 'ganache'

export class NodeConnectionFactory {
connectionOptions = {
accounts: [
{
balance: '0xFFFFFFFFFFFFFFFFFFFFFFFF',
secretKey: '0x8485898485bbe08a0a9b97fdf695aec8e9f1d196c589d4b6ff50a0232518b682'
}
],
network_id: 3,
logger: {
log(..._args) {}
},
default_balance_ether: 999999,
vmErrorsOnRPCResponse: true,
ws: true
}

createProvider() {
return ganache.provider(this.connectionOptions)
return ganache.provider<'ethereum'>({
chain: {
networkId: 3,
vmErrorsOnRPCResponse: true
},
wallet: {
accounts: [
{
balance: '0xFFFFFFFFFFFFFFFFFFFFFFFF',
secretKey: '0x8485898485bbe08a0a9b97fdf695aec8e9f1d196c589d4b6ff50a0232518b682'
}
],
defaultBalance: 999999
}
})
}

createServer() {
return ganache.server(this.connectionOptions)
return ganache.server<'ethereum'>({
chain: {
networkId: 3,
vmErrorsOnRPCResponse: true
},
wallet: {
accounts: [
{
balance: '0xFFFFFFFFFFFFFFFFFFFFFFFF',
secretKey: '0x8485898485bbe08a0a9b97fdf695aec8e9f1d196c589d4b6ff50a0232518b682'
}
],
defaultBalance: 999999
}
})
}
}
4 changes: 4 additions & 0 deletions test/helpers/testAllProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export function testAllProviders(doTest: (x: RequestManager) => void) {
}
})

it('initialize the provider', async () => {
await provider.initialize()
})

it('should get the network', async () => {
console.log('Network version:', await rm.net_version())
})
Expand Down
8 changes: 5 additions & 3 deletions test/integration.overload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ function doTest(requestManager: RequestManager) {
})

it('should get the balance', async () => {
const coinbase = await requestManager.eth_coinbase()
console.log(`> Coinbase`, coinbase)
const balance = await requestManager.eth_getBalance(coinbase, 'latest')
const accounts = await requestManager.eth_accounts()
const account = accounts[0]

console.log(`> Using account ${account}`)
const balance = await requestManager.eth_getBalance(account, 'latest')
console.log(`> Balance ${balance}`)
expect(balance.toNumber()).toBeGreaterThan(0)
})
Expand Down
8 changes: 4 additions & 4 deletions test/unit.eth-return-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('test types', () => {
// TODO: Move this to its own file
expect(() => toRPC({ id: null } as any)).toThrow()
expect(() => toRPC({ id: 1.1 } as any)).toThrow()
expect(() => toRPC({ id: 'asd' } as any)).toThrow()
expect(() => toRPC({ id: '0xaff' } as any)).toThrow()
expect(() => toRPC({ id: 1, method: '' } as any)).toThrow()
expect(() => toRPC({ id: 1, method: null } as any)).toThrow()
expect(() => toRPC({ id: 1, method: 123 } as any)).toThrow()
Expand All @@ -61,7 +61,7 @@ describe('test types', () => {
})

testReturnType(requestManager, 'web3_clientVersion', 'string')
testReturnType(requestManager, 'web3_sha3', 'string', 'asd')
testReturnType(requestManager, 'web3_sha3', 'string', '0xaff')
testReturnType(requestManager, 'net_version', 'string')
testReturnType(requestManager, 'net_peerCount', 'number')
testReturnType(requestManager, 'net_listening', 'boolean')
Expand All @@ -79,14 +79,14 @@ describe('test types', () => {

testReturnType(requestManager, 'eth_getCode', 'string', address, 'latest')

testReturnType(requestManager, 'eth_sign', 'string', address, 'asd')
testReturnType(requestManager, 'eth_sign', 'string', address, '0xaff')
testReturnType(requestManager, 'eth_getBlockByHash', 'object', '0x0', true)
testReturnType(requestManager, 'eth_newFilter', 'data', {})
testReturnType(requestManager, 'eth_newBlockFilter', 'data')
testReturnType(requestManager, 'eth_newPendingTransactionFilter', 'data')
testReturnType(requestManager, 'eth_getFilterChanges', 'array', '0x01')
testReturnType(requestManager, 'eth_getFilterLogs', 'array', '0x01')
testReturnType(requestManager, 'eth_getLogs', 'array', '0x01')
testReturnType(requestManager, 'eth_getLogs', 'array', ['0x01'])
testReturnType(requestManager, 'eth_uninstallFilter', 'boolean', '0x01')
testReturnType(requestManager, 'eth_uninstallFilter', 'boolean', '0x02')
testReturnType(requestManager, 'eth_uninstallFilter', 'boolean', '0x03')
Expand Down

0 comments on commit 232711a

Please sign in to comment.