diff --git a/programs/governance-registry/Cargo.toml b/programs/governance-registry/Cargo.toml index 596026a..937f87d 100644 --- a/programs/governance-registry/Cargo.toml +++ b/programs/governance-registry/Cargo.toml @@ -13,6 +13,7 @@ no-entrypoint = [] no-idl = [] cpi = ["no-entrypoint"] default = [] +localnet = [] [dependencies] anchor-lang = "0.18.0" diff --git a/programs/governance-registry/src/account.rs b/programs/governance-registry/src/account.rs index 82ca078..f789170 100644 --- a/programs/governance-registry/src/account.rs +++ b/programs/governance-registry/src/account.rs @@ -10,6 +10,11 @@ use std::convert::TryFrom; vote_weight_record!(crate::ID); /// Seconds in one day. +/// for localnet, to make testing of vesting possible, +/// set a low value so tests can just sleep for 10s to simulate a day +#[cfg(feature = "localnet")] +pub const SECS_PER_DAY: i64 = 10; +#[cfg(not(feature = "localnet"))] pub const SECS_PER_DAY: i64 = 86_400; /// Maximum number of days one can lock for. diff --git a/run-format.sh b/run-format.sh new file mode 100755 index 0000000..612025a --- /dev/null +++ b/run-format.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -euo pipefail + +yarn prettier --write tests +cargo fmt diff --git a/run-test.sh b/run-test.sh new file mode 100755 index 0000000..b59ea9b --- /dev/null +++ b/run-test.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -euo pipefail + +./run-format.sh && anchor test -- --features localnet \ No newline at end of file diff --git a/tests/governance-registry.ts b/tests/governance-registry.ts index 71b6771..814a35b 100644 --- a/tests/governance-registry.ts +++ b/tests/governance-registry.ts @@ -1,7 +1,7 @@ import * as assert from "assert"; import * as anchor from "@project-serum/anchor"; import { Program } from "@project-serum/anchor"; -import { createMintAndVault } from "@project-serum/common"; +import { createMintAndVault, sleep } from "@project-serum/common"; import BN from "bn.js"; import { PublicKey, @@ -273,6 +273,7 @@ describe("voting-rights", () => { }); it("Withdraws cliff locked A tokens", async () => { + await sleep(10000); const depositId = 0; const amount = new BN(10); await program.rpc.withdraw(depositId, amount, { @@ -329,6 +330,34 @@ describe("voting-rights", () => { assert.ok(deposit.rateIdx === 0); }); + it("Withdraws daily locked A tokens", async () => { + await sleep(10000); + const depositId = 1; + const amount = new BN(10); + await program.rpc.withdraw(depositId, amount, { + accounts: { + registrar, + voter, + exchangeVault: exchangeVaultA, + withdrawMint: mintA, + votingToken, + votingMint: votingMintA, + destination: godA, + authority: program.provider.wallet.publicKey, + tokenProgram, + }, + }); + + const voterAccount = await program.account.voter.fetch(voter); + const deposit = voterAccount.deposits[0]; + assert.ok(deposit.isUsed); + assert.ok(deposit.amountDeposited.toNumber() === 0); + assert.ok(deposit.rateIdx === 0); + + const vtAccount = await votingTokenClientA.getAccountInfo(votingToken); + assert.ok(vtAccount.amount.toNumber() === 0); + }); + it("Updates a vote weight record", async () => { await program.rpc.updateVoterWeightRecord({ accounts: {