diff --git a/src/classes/test/Contract/crv-abi.ts b/src/classes/test/Contract/crv-abi.ts index 72b4a1c..556d3d9 100644 --- a/src/classes/test/Contract/crv-abi.ts +++ b/src/classes/test/Contract/crv-abi.ts @@ -5,81 +5,6 @@ export const abi: JSONABI = // http://api.etherscan.io/api?module=contract&action=getabi&address=0x575CCD8e2D300e2377B43478339E364000318E2c&format=raw [ - { - name: 'Fund', - inputs: [ - { - type: 'address', - name: 'recipient', - indexed: true, - }, - { - type: 'uint256', - name: 'amount', - indexed: false, - }, - ], - anonymous: false, - type: 'event', - }, - { - name: 'Claim', - inputs: [ - { - type: 'address', - name: 'recipient', - indexed: true, - }, - { - type: 'uint256', - name: 'claimed', - indexed: false, - }, - ], - anonymous: false, - type: 'event', - }, - { - name: 'ToggleDisable', - inputs: [ - { - type: 'address', - name: 'recipient', - indexed: false, - }, - { - type: 'bool', - name: 'disabled', - indexed: false, - }, - ], - anonymous: false, - type: 'event', - }, - { - name: 'CommitOwnership', - inputs: [ - { - type: 'address', - name: 'admin', - indexed: false, - }, - ], - anonymous: false, - type: 'event', - }, - { - name: 'ApplyOwnership', - inputs: [ - { - type: 'address', - name: 'admin', - indexed: false, - }, - ], - anonymous: false, - type: 'event', - }, { outputs: [], inputs: [ diff --git a/src/classes/test/Contract/crv.test.ts b/src/classes/test/Contract/crv.test.ts index c8fe34b..4aab4a7 100644 --- a/src/classes/test/Contract/crv.test.ts +++ b/src/classes/test/Contract/crv.test.ts @@ -4,7 +4,6 @@ import { rpcUrls } from '../../../providers/test/rpc-urls'; import { Contract as EssentialEthContract } from '../../Contract'; import { abi } from './crv-abi'; -// The JSONABI const JSONABI = abi; const rpcURL = rpcUrls.mainnet; diff --git a/src/classes/test/Contract/ens.test.ts b/src/classes/test/Contract/ens.test.ts index aead724..07bfbf2 100644 --- a/src/classes/test/Contract/ens.test.ts +++ b/src/classes/test/Contract/ens.test.ts @@ -3,7 +3,6 @@ import { Contract as EssentialEthContract } from '../../Contract'; import { rpcUrls } from './../../../providers/test/rpc-urls'; import { ensABI } from './ens-abi'; -// The JSONABI const JSONABI = ensABI; const rpcURL = rpcUrls.mainnet; diff --git a/src/classes/test/Contract/fei.test.ts b/src/classes/test/Contract/fei.test.ts index 55ed414..7d59a3d 100644 --- a/src/classes/test/Contract/fei.test.ts +++ b/src/classes/test/Contract/fei.test.ts @@ -4,7 +4,6 @@ import { Contract as EssentialEthContract } from '../../Contract'; import { rpcUrls } from './../../../providers/test/rpc-urls'; import { feiABI } from './fei-abi'; -// The JSONABI const JSONABI = feiABI; const rpcURL = rpcUrls.mainnet; diff --git a/src/classes/test/Contract/jokerrace-abi.ts b/src/classes/test/Contract/jokerrace-abi.ts new file mode 100644 index 0000000..d989859 --- /dev/null +++ b/src/classes/test/Contract/jokerrace-abi.ts @@ -0,0 +1,10 @@ +import type { JSONABI } from '../../../types/Contract.types'; + +export const abi: JSONABI = [ + { + name: 'getAllAddressesThatHaveVoted', + outputs: [{ type: 'address[]', name: '' }], + inputs: [], + type: 'function', + }, +]; diff --git a/src/classes/test/Contract/jokerrace.integration.test.ts b/src/classes/test/Contract/jokerrace.integration.test.ts new file mode 100644 index 0000000..badc836 --- /dev/null +++ b/src/classes/test/Contract/jokerrace.integration.test.ts @@ -0,0 +1,26 @@ +import { JsonRpcProvider } from '../../../index'; +import { rpcUrls } from '../../../providers/test/rpc-urls'; +import { Contract as EssentialEthContract } from '../../Contract'; +import { abi } from './jokerrace-abi'; + +const JSONABI = abi; + +const rpcURL = rpcUrls.oeth; +const essentialEthProvider = new JsonRpcProvider(rpcURL); + +// https://optimistic.etherscan.io/address/0x5c11016ee4f8ad4ea2ab8b1b366f32d30d48a031#code +const contractAddress = '0x5c11016ee4f8ad4ea2ab8b1b366f32d30d48a031'; + +const essentialEthContract = new EssentialEthContract( + contractAddress, + JSONABI, + essentialEthProvider, +); +describe('jokerrace contract', () => { + it('should fetch "address[]"', async () => { + const addresses = await essentialEthContract.getAllAddressesThatHaveVoted(); + expect(Array.isArray(addresses)).toBe(true); + expect(addresses.length).toBeGreaterThan(18); + expect(addresses).toContain('0x0b06ca5DcC8A10Be0951d4E140D4312702B8D0EC'); + }); +}); diff --git a/src/classes/test/Contract/uni.test.ts b/src/classes/test/Contract/uni.test.ts index a2e71e9..e15824a 100644 --- a/src/classes/test/Contract/uni.test.ts +++ b/src/classes/test/Contract/uni.test.ts @@ -3,7 +3,6 @@ import { Contract as EssentialEthContract } from '../../Contract'; import { rpcUrls } from './../../../providers/test/rpc-urls'; import { uniswapABI } from './uniswap-abi'; -// The JSONABI const JSONABI = uniswapABI; const rpcURL = rpcUrls.mainnet; diff --git a/src/classes/utils/encode-decode-transaction.ts b/src/classes/utils/encode-decode-transaction.ts index c3750b1..a18afbe 100644 --- a/src/classes/utils/encode-decode-transaction.ts +++ b/src/classes/utils/encode-decode-transaction.ts @@ -49,7 +49,8 @@ function expandType(type: ContractTypes) { // https://docs.soliditylang.org/en/v0.8.7/types.html#integers if (type === 'uint[]') { return 'uint256[]'; - } else if (type === 'int[]') { + } + if (type === 'int[]') { return 'int256[]'; } return type; @@ -171,8 +172,17 @@ export function decodeRPCResponse( return hexToUtf8(hexToDecode); } // chunk response every 64 characters - const encodedOutputs = slicedResponse.match(/.{1,64}/g); - const outputs = (encodedOutputs || []).map((output: string, i: number) => { + const encodedOutputs = slicedResponse.match(/.{1,64}/g) || []; + if ( + jsonABIArgument?.outputs?.length === 1 && + jsonABIArgument.outputs[0].type === 'address[]' + ) { + const unformattedAddresses = encodedOutputs.slice(2); + return unformattedAddresses.map((unformattedAddress) => { + return toChecksumAddress(`0x${unformattedAddress.slice(24)}`); + }); + } + const outputs = encodedOutputs.map((output: string, i: number) => { const outputType = (rawOutputs || [])[i].type; switch (outputType) { case 'bool': @@ -187,6 +197,7 @@ export function decodeRPCResponse( return `0x${output}`; case 'uint8': return Number(hexToDecimal(`0x${output}`)); + default: throw new Error( `essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`,