@@ -293,9 +293,9 @@ func runSimnet(m *testing.M) (int, error) {
293293 participantAddr = participantAcct .Address
294294
295295 if v1 {
296- prepareV1Contractors ()
296+ prepareV1SimnetContractors ()
297297 } else {
298- prepareV0Contractors ()
298+ prepareV0SimnetContractors ()
299299 }
300300
301301 if err := ethClient .unlock (pw ); err != nil {
@@ -482,15 +482,15 @@ func runTestnet(m *testing.M) (int, error) {
482482 return code , nil
483483}
484484
485- func prepareV0Contractors () (err error ) {
486- return prepareContractors (newV0Contractor , newV0TokenContractor )
485+ func prepareV0SimnetContractors () (err error ) {
486+ return prepareSimnetContractors (newV0Contractor , newV0TokenContractor )
487487}
488488
489- func prepareV1Contractors () (err error ) {
490- return prepareContractors (newV1Contractor , newV1TokenContractor )
489+ func prepareV1SimnetContractors () (err error ) {
490+ return prepareSimnetContractors (newV1Contractor , newV1TokenContractor )
491491}
492492
493- func prepareContractors (c contractorConstructor , tc tokenContractorConstructor ) (err error ) {
493+ func prepareSimnetContractors (c contractorConstructor , tc tokenContractorConstructor ) (err error ) {
494494 if simnetContractor , err = c (dex .Simnet , simnetAddr , ethClient .contractBackend ()); err != nil {
495495 return fmt .Errorf ("new contractor error: %w" , err )
496496 }
@@ -1210,21 +1210,9 @@ func testInitiate(t *testing.T, assetID uint32) {
12101210
12111211 diff := new (big.Int ).Sub (wantBal , bal )
12121212 if diff .CmpAbs (new (big.Int )) != 0 {
1213-
1214- fmt .Println ("Original balance:" , fmtBig (originalBal ), ", New balance:" , fmtBig (bal ),
1215- ", Balance change:" , fmtBig (new (big.Int ).Sub (bal , originalBal )),
1216- ", Tx fees:" , fmtBig (txFee ), ", Swap val:" , fmtBig (dexeth .GweiToWei (totalVal )))
1217-
1218- cmd := exec .CommandContext (ctx , "./mine-alpha" , "5" )
1219- cmd .Dir = harnessCtlDir
1220- if err := cmd .Run (); err != nil {
1221- t .Fatalf ("error mining block after funding wallets" )
1222- }
1223-
1224- bal , _ := balance ()
1225-
1226- fmt .Println ("Original balance:" , fmtBig (originalBal ), ", New balance:" , fmtBig (bal ),
1227- ", Balance change:" , fmtBig (new (big.Int ).Sub (bal , originalBal )))
1213+ fmt .Println ("Original balance:" , fmtWei (originalBal ), ", New balance:" , fmtWei (bal ),
1214+ ", Balance change:" , fmtWei (new (big.Int ).Sub (bal , originalBal )),
1215+ ", Tx fees:" , fmtWei (txFee ), ", Swap val:" , fmtWei (dexeth .GweiToWei (totalVal )))
12281216 t .Fatalf ("%s: unexpected balance change: want %d got %d gwei, diff = %.9f gwei" ,
12291217 test .name , dexeth .WeiToGwei (wantBal ), dexeth .WeiToGwei (bal ), float64 (diff .Int64 ())/ dexeth .GweiFactor )
12301218 }
@@ -1441,18 +1429,18 @@ func testRedeem(t *testing.T, assetID uint32) {
14411429 finalStates : []dexeth.SwapStep {dexeth .SSRedeemed },
14421430 addAmt : true ,
14431431 },
1444- // {
1445- // name: "bad redeemer",
1446- // sleepNBlocks: 8,
1447- // redeemerClient: ethClient,
1448- // redeemer: simnetAcct,
1449- // redeemerContractor: c,
1450- // swaps: []*dex.SwapContractDetails{newDetails(4, 1)},
1451- // redemptions: []*asset.Redemption{newRedeem(secrets[4], secretHashes[4], 1, lockTime)},
1452- // isRedeemable: []bool{false},
1453- // finalStates: []dexeth.SwapStep{dexeth.SSInitiated},
1454- // addAmt: false,
1455- // },
1432+ {
1433+ name : "bad redeemer" ,
1434+ sleepNBlocks : 8 ,
1435+ redeemerClient : ethClient ,
1436+ redeemer : simnetAcct ,
1437+ redeemerContractor : c ,
1438+ swaps : []* dex.SwapContractDetails {newDetails (4 , 1 )},
1439+ redemptions : []* asset.Redemption {newRedeem (secrets [4 ], secretHashes [4 ], 1 , lockTime )},
1440+ isRedeemable : []bool {false },
1441+ finalStates : []dexeth.SwapStep {dexeth .SSInitiated },
1442+ addAmt : false ,
1443+ },
14561444 {
14571445 name : "bad secret" ,
14581446 sleepNBlocks : 8 ,
@@ -1573,9 +1561,9 @@ func testRedeem(t *testing.T, assetID uint32) {
15731561 expGas := gases .RedeemN (len (test .redemptions ))
15741562 // Ethereum is weird. For v1, if I use 42,000 here, it will often fail,
15751563 // using all of the gas, so presumably it fails because of insufficient
1576- // gas. But if I set a higher limit, the it will succeed, and oddly will
1577- // never use 42,000 gas. Why does it use more gas when I use a lower
1578- // limit?
1564+ // gas. But if I set a higher limit, then it will succeed, and oddly
1565+ // will never use 42,000 gas. Why does it use more gas when I use a
1566+ // lower limit?
15791567 txOpts , _ = test .redeemerClient .txOpts (ctx , 0 , expGas , dexeth .GweiToWei (maxFeeRate ))
15801568 tx , err = test .redeemerContractor .redeem (txOpts , test .redemptions )
15811569 if test .expectRedeemErr {
@@ -1603,9 +1591,6 @@ func testRedeem(t *testing.T, assetID uint32) {
16031591 if err != nil && expSuccess {
16041592 t .Fatalf ("%s: failed redeem transaction status: %v" , test .name , err )
16051593 }
1606- if expSuccess && receipt .GasUsed > expGas {
1607- t .Fatalf ("%s: gas used, %d, exceeds expected max %d" , test .name , receipt .GasUsed , expGas )
1608- }
16091594
16101595 fmt .Printf ("Gas used for %d redeems, success = %t: %d \n " , len (test .swaps ), expSuccess , receipt .GasUsed )
16111596
@@ -1952,11 +1937,9 @@ func testRefund(t *testing.T, assetID uint32) {
19521937
19531938 diff := new (big.Int ).Sub (wantBal , bal )
19541939 if diff .CmpAbs (dexeth .GweiToWei (1 )) >= 0 {
1955-
1956- fmt .Println ("Original balance:" , fmtBig (originalBal ), ", New balance:" , fmtBig (bal ),
1957- ", Balance change:" , fmtBig (new (big.Int ).Sub (bal , originalBal )),
1958- ", Tx fees:" , fmtBig (txFee ), ", Swap val:" , fmtBig (dexeth .GweiToWei (amt )))
1959-
1940+ fmt .Println ("Original balance:" , fmtWei (originalBal ), ", New balance:" , fmtWei (bal ),
1941+ ", Balance change:" , fmtWei (new (big.Int ).Sub (bal , originalBal )),
1942+ ", Tx fees:" , fmtWei (txFee ), ", Swap val:" , fmtWei (dexeth .GweiToWei (amt )))
19601943 t .Fatalf ("%s: unexpected balance change: want %d got %d, diff = %d" ,
19611944 test .name , dexeth .WeiToGwei (wantBal ), dexeth .WeiToGwei (bal ), dexeth .WeiToGwei (diff ))
19621945 }
@@ -2342,6 +2325,6 @@ func exportAccountsFromNode(node *node.Node) ([]accounts.Account, error) {
23422325 return ks .Accounts (), nil
23432326}
23442327
2345- func fmtBig (v * big.Int ) string {
2328+ func fmtWei (v * big.Int ) string {
23462329 return fmt .Sprintf ("%.9f gwei" , float64 (new (big.Int ).Div (v , big .NewInt (dexeth .GweiFactor )).Int64 ()))
23472330}
0 commit comments