Skip to content

Commit

Permalink
fix: contract tests
Browse files Browse the repository at this point in the history
  • Loading branch information
badurinantun committed Jun 13, 2022
1 parent 3a1150c commit f14fe11
Showing 1 changed file with 4 additions and 47 deletions.
51 changes: 4 additions & 47 deletions __tests__/contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { isBN } from 'bn.js';

import { Account, Contract, ContractFactory, Provider, defaultProvider, ec, stark } from '../src';
import { Account, Contract, ContractFactory, Provider, defaultProvider, stark } from '../src';
import { getSelectorFromName } from '../src/utils/hash';
import { BigNumberish, toBN } from '../src/utils/number';
import { compileCalldata } from '../src/utils/stark';
import {
compiledArgentAccount,
compiledErc20,
compiledMulticall,
compiledTypeTransformation,
testAccount,
} from './fixtures';

describe('class Contract {}', () => {
Expand Down Expand Up @@ -61,20 +61,6 @@ describe('class Contract {}', () => {
expect(res).toStrictEqual(result.res);
});

test('add 10 test ERC20 to account', async () => {
const response = await erc20.mint(wallet, '10');
expect(response.code).toBe('TRANSACTION_RECEIVED');

await defaultProvider.waitForTransaction(response.transaction_hash);
});

test('read balance after mint of that account', async () => {
const result = await erc20.balance_of(wallet);
const [res] = result;
expect(res).toStrictEqual(toBN(10));
expect(res).toStrictEqual(result.res);
});

test('read balance in a multicall', async () => {
const args1 = { user: wallet };
const args2 = {};
Expand Down Expand Up @@ -208,39 +194,24 @@ describe('class Contract {}', () => {
});

describe('Contract interaction with Account', () => {
let account: Account;
const account = testAccount;
let erc20: Contract;
let erc20Address: string;

beforeAll(async () => {
const starkKeyPair = ec.genKeyPair();
const starkKeyPub = ec.getStarkKey(starkKeyPair);
const { address } = await defaultProvider.deployContract({
contract: compiledArgentAccount,
addressSalt: starkKeyPub,
});
expect(address).toBeDefined();
account = new Account(defaultProvider, address, starkKeyPair);
const accountContract = new Contract(compiledArgentAccount.abi, address);
await accountContract.initialize(starkKeyPub, '0');

const erc20Response = await defaultProvider.deployContract({
contract: compiledErc20,
});
erc20Address = erc20Response.address;
erc20 = new Contract(compiledErc20.abi, erc20Address, defaultProvider);
expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
await defaultProvider.waitForTransaction(erc20Response.transaction_hash);

const mintResponse = await erc20.mint(account.address, '1000');

await defaultProvider.waitForTransaction(mintResponse.transaction_hash);
});

test('read balance of wallet', async () => {
const result = await erc20.balance_of(account.address);
const [res] = result;
expect(res).toStrictEqual(toBN(1000));
expect(res).toStrictEqual(toBN(0));
expect(res).toStrictEqual(result.res);
});

Expand All @@ -255,20 +226,6 @@ describe('class Contract {}', () => {
expect(res).toHaveProperty('amount');
expect(res).toHaveProperty('unit');
});

test('read balance of wallet', async () => {
const { res } = await erc20.balance_of(account.address);

expect(res).toStrictEqual(toBN(1000));
});

test('invoke contract by wallet owner', async () => {
const { transaction_hash, code } = await erc20.transfer(erc20Address, 10);
expect(code).toBe('TRANSACTION_RECEIVED');
await defaultProvider.waitForTransaction(transaction_hash);
const { res } = await erc20.balance_of(account.address);
expect(res).toStrictEqual(toBN(990));
});
});
});

Expand Down

0 comments on commit f14fe11

Please sign in to comment.