create a common method for `isWithdrawExited` - isWithdrawn, test for isWithdrawExited in erc721
MODIFY
src/pos/erc20.ts
src/pos/erc20.ts
@@ -189,16 +189,7 @@ export class ERC20 extends POSToken {
* @memberof ERC20
*/
isWithdrawExited(burnTxHash: string) {
- if (!burnTxHash) {
- throw new Error(`txHash not provided`);
- }
- return this.exitUtil.getExitHash(
- burnTxHash, Log_Event_Signature.Erc20Transfer
- ).then(exitHash => {
- return this.rootChainManager.isExitProcessed(
- exitHash
- );
- });
+ return this.isWithdrawn(burnTxHash, Log_Event_Signature.Erc20Transfer);
}
/**

MODIFY
src/pos/erc721.ts
src/pos/erc721.ts
@@ -23,7 +23,7 @@ export class ERC721 extends POSToken {
}, client, getContracts);
}
- private validateMany__(tokenIds) {
+ private validateMany_(tokenIds) {
if (tokenIds.length > 20) {
throw new Error('can not process more than 20 tokens');
}
@@ -178,7 +178,7 @@ export class ERC721 extends POSToken {
depositMany(tokenIds: TYPE_AMOUNT[], userAddress: string, option?: ITransactionOption) {
this.checkForRoot("depositMany");
- const tokensInUint256 = this.validateMany__(tokenIds);
+ const tokensInUint256 = this.validateMany_(tokenIds);
const amountInABI = this.client.parent.encodeParameters(
tokensInUint256,
@@ -209,7 +209,7 @@ export class ERC721 extends POSToken {
this.checkForChild("withdrawStartMany");
- const tokensInUint256 = this.validateMany__(tokenIds);
+ const tokensInUint256 = this.validateMany_(tokenIds);
return this.getContract().then(contract => {
const method = contract.method(
"withdrawBatch",
@@ -280,29 +280,15 @@ export class ERC721 extends POSToken {
}
isWithdrawExited(txHash: string) {
- if (!txHash) {
- throw new Error(`txHash not provided`);
- }
- return this.exitUtil.getExitHash(
+ return this.isWithdrawn(
txHash, Log_Event_Signature.Erc721Transfer
- ).then(exitHash => {
- return this.rootChainManager.isExitProcessed(
- exitHash
);
- });
}
isWithdrawExitedMany(txHash: string) {
- if (!txHash) {
- throw new Error(`txHash not provided`);
- }
- return this.exitUtil.getExitHash(
+ return this.isWithdrawn(
txHash, Log_Event_Signature.Erc721BatchTransfer
- ).then(exitHash => {
- return this.rootChainManager.isExitProcessed(
- exitHash
);
- });
}
/**

MODIFY
src/pos/pos_token.ts
src/pos/pos_token.ts
@@ -14,11 +14,11 @@ export class POSToken extends BaseToken<IPOSClientConfig> {
super(contractParam, client);
}
- get rootChainManager() {
+ protected get rootChainManager() {
return this.getPOSContracts().rootChainManager;
}
- get exitUtil() {
+ protected get exitUtil() {
return this.getPOSContracts().exitUtil;
}
@@ -40,4 +40,17 @@ export class POSToken extends BaseToken<IPOSClientConfig> {
this.predicateAddress = predicateAddress;
return predicateAddress;
}
+
+ protected isWithdrawn(txHash: string, eventSignature: string) {
+ if (!txHash) {
+ throw new Error(`txHash not provided`);
+ }
+ return this.exitUtil.getExitHash(
+ txHash, eventSignature
+ ).then(exitHash => {
+ return this.rootChainManager.isExitProcessed(
+ exitHash
+ );
+ });
+ }
}
\ No newline at end of file

MODIFY
test/debug.js
test/debug.js
@@ -36,6 +36,7 @@ const execute = async () => {
const mumbaiERC20Token = client.erc20(mumbaiERC20);
const goerliERC20Token = client.erc20(goerliERC20, true);
const goerliERC721Token = client.erc721(pos.parent.erc721, true);
+ const mumbaiERC721Token = client.erc721(pos.child.erc721);
@@ -47,19 +48,19 @@ const execute = async () => {
// );
// return console.log("balance", balance);
- // const tokens = await goerliERC720Token.getAllTokens(
+ // const tokens = await mumbaiERC721Token.getAllTokens(
// from
// );
// return console.log("tokens", tokens);
- const tx = await goerliERC721Token.deposit(10, from, {
- returnTransaction: true
+ const tx = await goerliERC721Token.withdrawExit('0x2697a930ae883dd28c40a263a6a3b4d41a027cab56836de987ed2c2896abcdeb', {
+ // returnTransaction: true
});
- console.log('tx', tx);
+ // console.log('tx', tx);
// // setProofApi("https://apis.matic.network")
// // const tx = await goerliERC20Token.withdrawExit('0xd6f7f4c6052611761946519076de28fbd091693af974e7d4abc1b17fd7926fd7');
- // console.log("txHash", await tx.getTransactionHash());
- // console.log("txReceipt", await tx.getReceipt());
+ console.log("txHash", await tx.getTransactionHash());
+ console.log("txReceipt", await tx.getReceipt());
//txhash to plasma exit - 0x63aa095e0d6ee8698399b871daa202eb5522933e2d94c5929cf0fb86b6b0c628
const tokenId = '60399350241383852757821046101235634991156913804166740995010931519407953501076'

MODIFY
test/specs/erc721.spec.ts
test/specs/erc721.spec.ts
@@ -37,6 +37,12 @@ describe('ERC721', () => {
expect(allTokens).to.be.an('array').length(tokensCount);
})
+ it('isWithdrawExited', async () => {
+ // const exitHash = '0xa3ed203336807249dea53dc99434e2d06b71c85f55c89ee49ca10244ab3dbcf5';
+ const isExited = await erc721Parent.isWithdrawExited('0x2697a930ae883dd28c40a263a6a3b4d41a027cab56836de987ed2c2896abcdeb');
+ expect(isExited).equal(true);
+ })
+
it('transfer return tx', async () => {
const allTokensFrom = await erc721Child.getAllTokens(from);
const targetToken = allTokensFrom[0];
@@ -62,7 +68,13 @@ describe('ERC721', () => {
expect(result['to'].toLowerCase()).equal(erc721.parent.toLowerCase());
})
- // return;
+ it('withdrawStart return tx', async () => {
+ const allTokens = await erc721Child.getAllTokens(from);
+ const result = await erc721Child.withdrawStart(allTokens[0], {
+ returnTransaction: true
+ });
+ expect(result['to'].toLowerCase()).equal(erc721.child.toLowerCase());
+ })
it('transfer write', async () => {
const allTokensFrom = await erc721Child.getAllTokens(from);

create a common method for `isWithdrawExited` - isWithdrawn, test for isWithdrawExited in erc721