Skip to content

Commit

Permalink
Extra staking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Oct 9, 2024
1 parent 11493e6 commit f219d5a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions convex-core/src/test/java/convex/core/StakingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

0 comments on commit f219d5a

Please sign in to comment.