small additions to contract unit tests (#388)

This commit is contained in:
noot
2023-04-19 18:23:36 +02:00
committed by GitHub
parent 59c10d8d03
commit c4a5e12615

View File

@@ -279,6 +279,11 @@ func testClaim(t *testing.T, asset ethcommon.Address, newLogIndex int, value *bi
Nonce: nonce,
}
// ensure we can't claim before setting contract to Ready
txOpts = *authOrig
_, err = contract.Claim(&txOpts, swap, proof.Secret())
require.ErrorContains(t, err, "VM Exception while processing transaction: revert")
// set contract to Ready
txOpts = *authOrig
tx, err = contract.SetReady(&txOpts, swap)
@@ -288,11 +293,8 @@ func testClaim(t *testing.T, asset ethcommon.Address, newLogIndex int, value *bi
require.NoError(t, err)
// now let's try to claim
var s [32]byte
secret := proof.Secret()
copy(s[:], secret[:])
txOpts = *authOrig
tx, err = contract.Claim(&txOpts, swap, s)
tx, err = contract.Claim(&txOpts, swap, proof.Secret())
require.NoError(t, err)
receipt, err = block.WaitForReceipt(context.Background(), conn, tx.Hash())
require.NoError(t, err)
@@ -364,10 +366,7 @@ func testRefundBeforeT0(t *testing.T, asset ethcommon.Address, erc20Contract *Te
}
// now let's try to refund
var s [32]byte
secret := proof.Secret()
copy(s[:], secret[:])
tx, err = contract.Refund(auth, swap, s)
tx, err = contract.Refund(auth, swap, proof.Secret())
require.NoError(t, err)
receipt, err = block.WaitForReceipt(context.Background(), conn, tx.Hash())
require.NoError(t, err)
@@ -409,7 +408,7 @@ func testRefundAfterT1(t *testing.T, asset ethcommon.Address, erc20Contract *Tes
}
nonce := big.NewInt(0)
timeout := big.NewInt(1) // T1 expires before we get the receipt for new_swap TX
timeout := big.NewInt(3)
auth.Value = defaultSwapValue
tx, err = contract.NewSwap(auth, [32]byte{}, cmt, addr, timeout, timeout,
asset, defaultSwapValue, nonce)
@@ -427,8 +426,8 @@ func testRefundAfterT1(t *testing.T, asset ethcommon.Address, erc20Contract *Tes
t0, t1, err := GetTimeoutsFromLog(receipt.Logs[newLogIndex])
require.NoError(t, err)
<-time.After(time.Until(time.Unix(t1.Int64()+1, 0)))
// ensure we can't refund between T0 and T1
<-time.After(time.Until(time.Unix(t0.Int64()+1, 0)))
swap := SwapCreatorSwap{
Owner: addr,
Claimer: addr,
@@ -441,11 +440,16 @@ func testRefundAfterT1(t *testing.T, asset ethcommon.Address, erc20Contract *Tes
Nonce: nonce,
}
// now let's try to refund
var s [32]byte
secret := proof.Secret()
copy(s[:], secret[:])
tx, err = contract.Refund(auth, swap, s)
tx, err = contract.Refund(auth, swap, secret)
require.NoError(t, err)
_, err = block.WaitForReceipt(context.Background(), conn, tx.Hash())
require.ErrorContains(t, err, "VM Exception while processing transaction: revert")
<-time.After(time.Until(time.Unix(t1.Int64()+1, 0)))
// now let's try to refund
tx, err = contract.Refund(auth, swap, secret)
require.NoError(t, err)
receipt, err = block.WaitForReceipt(context.Background(), conn, tx.Hash())
require.NoError(t, err)
@@ -508,9 +512,7 @@ func TestSwapCreator_MultipleSwaps(t *testing.T) {
res, err := dleq.Verify(proof)
require.NoError(t, err)
secret := proof.Secret()
copy(sc.secret[:], secret[:])
sc.secret = proof.Secret()
sc.walletKey = tests.GetTestKeyByIndex(t, i)
addrSwap := crypto.PubkeyToAddress(*sc.walletKey.Public().(*ecdsa.PublicKey))