Skip to content

Commit

Permalink
Update integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Jun 10, 2021
1 parent 7818de1 commit a8764f2
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions core/tests/ts-tests/tests/register-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
import { Tester } from './tester';
import { utils } from 'ethers';
import { expect } from 'chai';
import { Wallet, types } from 'zksync';
import { Wallet, types, ETHProxy } from 'zksync';
type TokenLike = types.TokenLike;

function readContractCode(name: string) {
Expand All @@ -25,6 +25,32 @@ declare module './tester' {
}

Tester.prototype.testRegisterFactory = async function (wallet: Wallet, feeToken: TokenLike) {
const contractAddress = await wallet.provider.getContractAddress();
const ethProxy = new ETHProxy(wallet.ethSigner.provider!, contractAddress);
const defaultNFTFactoryAddress = (await ethProxy.getGovernanceContract().defaultFactory()).toLowerCase();

const type = 'MintNFT';
const contentHash = utils.randomBytes(32);
let { totalFee: fee } = await this.syncProvider.getTransactionFee(type, wallet.address(), feeToken);

const handle = await wallet.mintNFT({
recipient: wallet.address(),
contentHash,
feeToken,
fee
});

this.runningFee = this.runningFee.add(fee);
const receipt = await handle.awaitVerifyReceipt();
expect(receipt.success, `Mint NFT failed with a reason: ${receipt.failReason}`).to.be.true;

const state = await wallet.getAccountState();
const nft: any = Object.values(state.verified.nfts)[0];

let nftInfo = await wallet.provider.getNFT(nft.id);
expect(nftInfo.currentFactory, 'NFT info before withdrawing is wrong').to.eql(defaultNFTFactoryAddress);
expect(nftInfo.withdrawnFactory, 'NFT info before withdrawing is wrong').to.be.null;

const contract = await deployContract(
wallet.ethSigner,
readFactoryCode(),
Expand All @@ -44,36 +70,24 @@ Tester.prototype.testRegisterFactory = async function (wallet: Wallet, feeToken:
});
await tx.wait();

const type = 'MintNFT';
const contentHash = utils.randomBytes(32);
let { totalFee: fee } = await this.syncProvider.getTransactionFee(type, wallet.address(), feeToken);

const handle = await wallet.mintNFT({
recipient: wallet.address(),
contentHash,
feeToken,
fee
});

this.runningFee = this.runningFee.add(fee);
const receipt = await handle.awaitVerifyReceipt();
expect(receipt.success, `Mint NFT failed with a reason: ${receipt.failReason}`).to.be.true;
const state = await wallet.getAccountState();
let { totalFee: withdrawFee } = await this.syncProvider.getTransactionFee(
'WithdrawNFT',
wallet.address(),
feeToken
);
const nft: any = Object.values(state.committed.nfts)[0];
const handleWithdraw = await wallet.withdrawNFT({
to: wallet.address(),
token: nft.id,
feeToken,
fee: withdrawFee
});
const receipt_withdraw = await handleWithdraw.awaitVerifyReceipt();
expect(receipt_withdraw.success, `Withdraw NFT failed with a reason: ${receipt_withdraw.failReason}`).to.be.true;
const receiptWithdraw = await handleWithdraw.awaitVerifyReceipt();
expect(receiptWithdraw.success, `Withdraw NFT failed with a reason: ${receiptWithdraw.failReason}`).to.be.true;
const owner = await contract.ownerOf(nft.id);
expect(owner == wallet.address(), 'Contract minting is wrong');
this.runningFee = this.runningFee.add(withdrawFee);

nftInfo = await wallet.provider.getNFT(nft.id);
expect(nftInfo.currentFactory, 'NFT info after withdrawing is wrong').to.eql(contract.address.toLowerCase());
expect(nftInfo.withdrawnFactory, 'NFT info after withdrawing is wrong').to.eql(contract.address.toLowerCase());
};

0 comments on commit a8764f2

Please sign in to comment.