Skip to content

Commit

Permalink
Update sdk and add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Nov 8, 2021
1 parent 67bb8c1 commit d343793
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/tests/ts-tests/tests/mint-nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ Tester.prototype.testMintNFT = async function (
expect(receipt.success, `Mint NFT failed with a reason: ${receipt.failReason}`).to.be.true;

const balanceAfter = await wallet.getBalance(feeToken);

expect(balanceBefore.sub(balanceAfter).eq(fee), 'Wrong amount in wallet after withdraw').to.be.true;

const nftId = await wallet.provider.getNFTIdByTxHash(handle.txHash);
expect(nftId).to.exist;

const state = await receiver.getAccountState();
const nft = Object.values(state.committed.nfts)[0];
expect(nft).to.exist;
expect(nft.contentHash).eq(utils.hexlify(contentHash));
expect(nft.id).to.eq(nftId);

return nft;
};
Expand Down
1 change: 1 addition & 0 deletions sdk/zksync.js/src/provider-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export abstract class SyncProvider {
abstract getNFT(id: number): Promise<NFTInfo>;
abstract getNFTOwner(id: number): Promise<number>;
abstract toggle2FA(data: Toggle2FARequest): Promise<boolean>;
abstract getNFTIdByTxHash(txHash: string): Promise<number>;

async updateTokenSet(): Promise<void> {
const updatedTokenSet = new TokenSet(await this.getTokens());
Expand Down
4 changes: 4 additions & 0 deletions sdk/zksync.js/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ export class Provider extends SyncProvider {
return result.success;
}

async getNFTIdByTxHash(txHash: string): Promise<number> {
return await this.transport.request('get_nft_id_by_tx_hash', [txHash]);
}

async disconnect() {
return await this.transport.disconnect();
}
Expand Down
8 changes: 8 additions & 0 deletions sdk/zksync.js/src/rest-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ export class RestProvider extends SyncProvider {
return this.parseResponse(await this.getNFTOwnerDetailed(id));
}

async getNFTIdByTxHashDetailed(txHash: string): Promise<Response<number>> {
return await this.get(`${this.address}/tokens/nft_id_by_tx_hash/${txHash}`);
}

async getNFTIdByTxHash(txHash: string): Promise<number> {
return this.parseResponse(await this.getNFTIdByTxHashDetailed(txHash));
}

async notifyAnyTransaction(hash: string, action: 'COMMIT' | 'VERIFY'): Promise<types.ApiTxReceipt> {
while (true) {
let transactionStatus = await this.txStatus(hash);
Expand Down

0 comments on commit d343793

Please sign in to comment.