Skip to content

Commit

Permalink
fix: rpc provider account tests
Browse files Browse the repository at this point in the history
  • Loading branch information
badurinantun committed Jul 13, 2022
1 parent fc3b484 commit b2fc530
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
17 changes: 8 additions & 9 deletions __tests__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

Expand Down
11 changes: 8 additions & 3 deletions __tests__/rpcProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -225,7 +231,6 @@ describe('RPCProvider', () => {
calldata: [erc20.address, '10'],
});

console.log({ overall_fee });
expect(isBN(overall_fee)).toBe(true);
});

Expand Down
14 changes: 0 additions & 14 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,6 @@ export class RPCProvider implements ProviderInterface {
functionInvocation: Invocation,
details: InvocationsDetails
): Promise<InvokeFunctionResponse> {
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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit b2fc530

Please sign in to comment.