From b2fc53004a1e52149b3fa4e7357c3ade1d01cd4a Mon Sep 17 00:00:00 2001 From: Antun Badurina Date: Wed, 13 Jul 2022 21:54:19 +0200 Subject: [PATCH] fix: rpc provider account tests --- __tests__/fixtures.ts | 17 ++++++++--------- __tests__/rpcProvider.test.ts | 11 ++++++++--- src/provider/rpc.ts | 14 -------------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/__tests__/fixtures.ts b/__tests__/fixtures.ts index c64b76917..8bc3d76cb 100644 --- a/__tests__/fixtures.ts +++ b/__tests__/fixtures.ts @@ -36,23 +36,22 @@ export const getTestProvider = () => { // test account with fee token balance export const getTestAccount = (provider = getTestProvider(), isDevnet = false) => { + let testAccountAddress = process.env.TEST_ACCOUNT_ADDRESS; + let testAccountPrivateKey = process.env.TEST_ACCOUNT_PRIVATE_KEY; + if (!isDevnet) { - if (!process.env.TEST_ACCOUNT_PRIVATE_KEY) { + if (!testAccountPrivateKey) { throw new Error('TEST_ACCOUNT_PRIVATE_KEY is not set'); } - if (!process.env.TEST_ACCOUNT_ADDRESS) { + if (!testAccountAddress) { throw new Error('TEST_ACCOUNT_ADDRESS is not set'); } + } else { + testAccountAddress = DEFAULT_TEST_ACCOUNT_ADDRESS; + testAccountPrivateKey = DEFAULT_TEST_ACCOUNT_PRIVATE_KEY; } - const testAccountAddress = isDevnet - ? DEFAULT_TEST_ACCOUNT_ADDRESS - : (process.env.TEST_ACCOUNT_ADDRESS as string); - const testAccountPrivateKey = isDevnet - ? DEFAULT_TEST_ACCOUNT_PRIVATE_KEY - : (process.env.TEST_ACCOUNT_PRIVATE_KEY as string); - return new Account(provider, testAccountAddress, ec.getKeyPair(testAccountPrivateKey)); }; diff --git a/__tests__/rpcProvider.test.ts b/__tests__/rpcProvider.test.ts index eb3cbb736..bfbab81ce 100644 --- a/__tests__/rpcProvider.test.ts +++ b/__tests__/rpcProvider.test.ts @@ -205,8 +205,14 @@ describe('RPCProvider', () => { account = getTestAccount(rpcProvider, false); expect(account).toBeInstanceOf(Account); - // Using predeployed contract as RPC node has issues with using recent deployed contracts - erc20Address = '0x649c8b8dbb19009551120c364208bad865f06d4b12ecd3e7109421d8b22968e'; + const erc20Response = await provider.deployContract({ + contract: compiledErc20, + }); + + erc20Address = erc20Response.contract_address!; + erc20 = new Contract(compiledErc20.abi, erc20Address, provider); + + await provider.waitForTransaction(erc20Response.transaction_hash); erc20 = new Contract(compiledErc20.abi, erc20Address, provider); const mintResponse = await account.execute({ @@ -225,7 +231,6 @@ describe('RPCProvider', () => { calldata: [erc20.address, '10'], }); - console.log({ overall_fee }); expect(isBN(overall_fee)).toBe(true); }); diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index 9e96e5007..9eaf1fac2 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -181,17 +181,6 @@ export class RPCProvider implements ProviderInterface { functionInvocation: Invocation, details: InvocationsDetails ): Promise { - console.log([ - { - contract_address: functionInvocation.contractAddress, - entry_point_selector: getSelectorFromName(functionInvocation.entrypoint), - calldata: parseCalldata(functionInvocation.calldata), - }, - bigNumberishArrayToDecimalStringArray(functionInvocation.signature || []), - toHex(toBN(details.maxFee || 0)), - toHex(toBN(details.version || 0)), - ]); - return this.fetchEndpoint('starknet_addInvokeTransaction', [ { contract_address: functionInvocation.contractAddress, @@ -222,7 +211,6 @@ export class RPCProvider implements ProviderInterface { public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) { let onchain = false; - // TODO: optimize this let retries = 100; while (!onchain) { @@ -234,7 +222,6 @@ export class RPCProvider implements ProviderInterface { try { // eslint-disable-next-line no-await-in-loop const res = await this.getTransactionReceipt(txHash); - console.log({ res }); if (successStates.includes(res.status)) { onchain = true; @@ -245,7 +232,6 @@ export class RPCProvider implements ProviderInterface { throw error; } } catch (error: unknown) { - console.log(error); if (error instanceof Error && errorStates.includes(error.message)) { throw error; }