From f219d5aab6079a0a599e7edb210d01594f691d04 Mon Sep 17 00:00:00 2001 From: mikera Date: Wed, 9 Oct 2024 17:12:22 +0100 Subject: [PATCH] Extra staking tests --- .../test/java/convex/core/StakingTest.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/convex-core/src/test/java/convex/core/StakingTest.java b/convex-core/src/test/java/convex/core/StakingTest.java index 741a10899..87120f4a9 100644 --- a/convex-core/src/test/java/convex/core/StakingTest.java +++ b/convex-core/src/test/java/convex/core/StakingTest.java @@ -2,6 +2,7 @@ import static convex.test.Assertions.assertArgumentError; import static convex.test.Assertions.assertFundsError; +import static convex.test.Assertions.assertCVMEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; @@ -43,24 +44,29 @@ public void testStake() { @Test public void testStakeReturns() { - Context ctx0 = context(); - assertEquals(1000L, evalL(ctx0, "(set-stake " + InitTest.FIRST_PEER_KEY + " 1000)")); + Context ctx = context(); + ctx=exec(ctx,"(set-stake " + InitTest.FIRST_PEER_KEY + " 1000)"); + assertCVMEquals(1000L, ctx.getResult()); + assertEquals(HERO_BALANCE-1000,ctx.getBalance()); // check initial balance restored + ctx=exec(ctx,"(set-stake " + InitTest.FIRST_PEER_KEY + " 0)"); + assertCVMEquals(-1000L, ctx.getResult()); + assertEquals(HERO_BALANCE,ctx.getBalance()); // check initial balance restored } @Test public void testBadStake() { - Context ctx0 = context(); + Context ctx = context(); // TODO: new test since HERO is now a peer manager // not a peer, should be state error //assertStateError(ctx0.setDelegatedStake(InitTest.HERO_KEYPAIR.getAccountKey(), 1000)); // bad arguments, out of range - assertArgumentError(ctx0.setDelegatedStake(InitTest.FIRST_PEER_KEY, -1)); - assertArgumentError(ctx0.setDelegatedStake(InitTest.FIRST_PEER_KEY, Long.MAX_VALUE)); + assertArgumentError(ctx.setDelegatedStake(InitTest.FIRST_PEER_KEY, -1)); + assertArgumentError(ctx.setDelegatedStake(InitTest.FIRST_PEER_KEY, Long.MAX_VALUE)); // insufficient funds for stake - assertFundsError(ctx0.setDelegatedStake(InitTest.FIRST_PEER_KEY, Constants.MAX_SUPPLY)); - assertFundsError(ctx0.setDelegatedStake(InitTest.FIRST_PEER_KEY, ctx0.getBalance(InitTest.HERO) + 1)); + assertFundsError(ctx.setDelegatedStake(InitTest.FIRST_PEER_KEY, Constants.MAX_SUPPLY)); + assertFundsError(ctx.setDelegatedStake(InitTest.FIRST_PEER_KEY, HERO_BALANCE + 1)); } }