Skip to content

Commit

Permalink
fix: contract tests
Browse files Browse the repository at this point in the history
  • Loading branch information
badurinantun committed Jul 8, 2022
1 parent 255fd3c commit ffb6a12
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
31 changes: 11 additions & 20 deletions __tests__/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,20 @@ describe('class Contract {}', () => {
let contract: Contract;

beforeAll(async () => {
const { code, transaction_hash, address } = await provider.deployContract({
const { transaction_hash, contract_address } = await provider.deployContract({
contract: compiledErc20,
});
erc20 = new Contract(compiledErc20.abi, address!, provider);
expect(code).toBe('TRANSACTION_RECEIVED');
erc20 = new Contract(compiledErc20.abi, contract_address!, provider);
await provider.waitForTransaction(transaction_hash);
// Deploy Multicall

const {
code: m_code,
transaction_hash: m_transaction_hash,
address: multicallAddress,
} = await provider.deployContract({
contract: compiledMulticall,
});
const { transaction_hash: m_transaction_hash, contract_address: multicallAddress } =
await provider.deployContract({
contract: compiledMulticall,
});

contract = new Contract(compiledMulticall.abi, multicallAddress!, provider);

expect(m_code).toBe('TRANSACTION_RECEIVED');

await provider.waitForTransaction(m_transaction_hash);
});

Expand Down Expand Up @@ -92,11 +86,10 @@ describe('class Contract {}', () => {
let contract: Contract;

beforeAll(async () => {
const { code, transaction_hash, address } = await provider.deployContract({
const { transaction_hash, contract_address } = await provider.deployContract({
contract: compiledTypeTransformation,
});
contract = new Contract(compiledTypeTransformation.abi, address!, provider);
expect(code).toBe('TRANSACTION_RECEIVED');
contract = new Contract(compiledTypeTransformation.abi, contract_address!, provider);
await provider.waitForTransaction(transaction_hash);
});

Expand Down Expand Up @@ -205,9 +198,8 @@ describe('class Contract {}', () => {
const erc20Response = await provider.deployContract({
contract: compiledErc20,
});
erc20Address = erc20Response.address!;
erc20Address = erc20Response.contract_address!;
erc20 = new Contract(compiledErc20.abi, erc20Address, provider);
expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
await provider.waitForTransaction(erc20Response.transaction_hash);
});

Expand All @@ -229,12 +221,11 @@ describe('class Contract {}', () => {
describe('class ContractFactory {}', () => {
let erc20Address: string;
beforeAll(async () => {
const { code, transaction_hash, address } = await provider.deployContract({
const { transaction_hash, contract_address } = await provider.deployContract({
contract: compiledErc20,
});
expect(code).toBe('TRANSACTION_RECEIVED');
await provider.waitForTransaction(transaction_hash);
erc20Address = address!;
erc20Address = contract_address!;
});
test('deployment of new contract', async () => {
const factory = new ContractFactory(compiledErc20, provider);
Expand Down
9 changes: 3 additions & 6 deletions src/contract/contractFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@ export class ContractFactory {
constructorCalldata?: RawCalldata,
addressSalt?: BigNumberish
): Promise<Contract> {
const { address, code, transaction_hash } = await this.providerOrAccount.deployContract({
const { contract_address, transaction_hash } = await this.providerOrAccount.deployContract({
contract: this.compiledContract,
constructorCalldata,
addressSalt,
});
assert(
code === 'TRANSACTION_RECEIVED' && Boolean(address),
'Deployment of the contract failed'
);
assert(Boolean(contract_address), 'Deployment of the contract failed');

const contractInstance = new Contract(
this.compiledContract.abi,
address!,
contract_address!,
this.providerOrAccount
);
contractInstance.deployTransactionHash = transaction_hash;
Expand Down
2 changes: 1 addition & 1 deletion src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class Provider implements ProviderInterface {
return this.provider.declareContract(payload);
}

public async waitForTransaction(txHash: BigNumberish, retryInterval: number): Promise<void> {
public async waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void> {
return this.provider.waitForTransaction(txHash, retryInterval);
}
}

0 comments on commit ffb6a12

Please sign in to comment.