@@ -4,41 +4,36 @@ async function main() {
44 const accounts = await hre . ethers . getSigners ( ) ;
55 const alice = accounts [ 0 ] . address ;
66 const bob = accounts [ 1 ] . address ;
7+ const timeoutHeight = [ [ 1 , 10000000 ] , 0 ] ;
8+ try {
9+ const token = await util . readContract ( "ERC20Token" ) ;
10+ const transfer = await util . readContract ( "ICS20Transfer" ) ;
711
8- const port = "transfer" ;
9- const channel = "channel-0" ;
10- const timeoutHeight = 10000000 ;
11- const mintAmount = 100 ;
12- const sendingAmount = 20
12+ const before = await token . balanceOf ( alice )
13+ console . log ( "before = " , before . toString ( ) )
1314
14- try {
15- // Mint
16- const bank = await util . readContract ( "ICS20Bank" ) ;
17- const mintResult = await bank . mint ( alice , "simple_erc_20_token_for_test" , mintAmount , {
15+ const escrowBefore = await token . balanceOf ( transfer . target )
16+ console . log ( "escrow before = " , escrowBefore . toString ( ) )
17+
18+ // Deposit and SendTransfer
19+ await token . approve ( transfer . target , util . config . amount , { from : alice } ) . then ( tx => tx . wait ( ) ) ;
20+ const depositResult = await transfer . depositSendTransfer ( util . config . channel , token . target , util . config . amount , bob , timeoutHeight , {
1821 from : alice
19- } ) ;
20- const mintReceipt = await mintResult . wait ( )
21- console . log ( "mint success" , mintReceipt . hash ) ;
22-
23- // Send to counterparty chain
24- const transfer = await util . readContract ( "ICS20TransferBank" ) ;
25- const transferResult = await transfer . sendTransfer ( "simple_erc_20_token_for_test" , sendingAmount , bob , port , channel , timeoutHeight , {
26- from : alice ,
27- } ) ;
28- const transferReceipt = await transferResult . wait ( )
29- console . log ( "send success" , transferReceipt . hash ) ;
22+ } )
23+ const depositReceipt = await depositResult . wait ( )
24+ console . log ( "depositSendTransfer success" , depositReceipt . hash ) ;
3025
3126 // Check reduced amount
32- const aliceAmount = await bank . balanceOf ( alice , "simple_erc_20_token_for_test" )
33- console . log ( "after = " , aliceAmount . toString ( ) )
34- if ( parseInt ( aliceAmount . toString ( ) , 10 ) !== mintAmount - sendingAmount ) {
27+ const after = await token . balanceOf ( alice )
28+ console . log ( "after = " , after . toString ( ) )
29+ if ( parseInt ( after . toString ( ) , 10 ) !== Number ( before ) - util . config . amount ) {
3530 throw new Error ( "alice amount error" ) ;
3631 }
3732
3833 // Check escrow balance
39- const escrowAmount = await bank . balanceOf ( transfer . target , "simple_erc_20_token_for_test" )
40- console . log ( "escrow = " , escrowAmount . toString ( ) )
41- if ( parseInt ( escrowAmount . toString ( ) , 10 ) !== sendingAmount ) {
34+ const escrowAfter = await token . balanceOf ( transfer . target )
35+ console . log ( "escrow after = " , escrowAfter . toString ( ) )
36+ if ( parseInt ( escrowAfter . toString ( ) , 10 ) !== Number ( escrowBefore ) + util . config . amount ) {
4237 throw new Error ( "escrow amount error" ) ;
4338 }
4439
0 commit comments