diff --git a/cli/src/main.rs b/cli/src/main.rs index 8bdbc15c8..a5d43a204 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -50,6 +50,9 @@ pub enum Command { #[clap(short, long)] keypair: Option, }, + /// Not yet implemented. Please use `solana program deploy` command to + /// upgrade your program. + Upgrade {}, } fn main() -> Result<()> { @@ -67,6 +70,10 @@ fn main() -> Result<()> { idl(file, Some(&PathBuf::from(out.unwrap()))) } Command::Deploy { url, keypair } => deploy(url, keypair), + Command::Upgrade {} => { + println!("This command is not yet implemented. Please use `solana program deploy`."); + Ok(()) + } } } @@ -296,7 +303,7 @@ fn test() -> Result<()> { // Run the tests. if let Err(e) = std::process::Command::new("mocha") .arg("-t") - .arg("10000") + .arg("1000000") .arg("tests/") .env("ANCHOR_PROVIDER_URL", cfg.cluster.url()) .stdout(Stdio::inherit()) @@ -424,16 +431,24 @@ fn run_hosted_deploy(url: &str) -> Result<()> { fn deploy_ws(url: &str, keypair: &str) -> Result> { let mut programs = vec![]; println!("Deploying workspace to {}...", url); + println!("Upgrade authority: {}", keypair); for program in read_all_programs()? { let binary_path = format!("target/deploy/{}.so", program.lib_name); + + // The Solana CLI doesn't redeploy a program if this file exists. + // So remove it to make deploys explicit. + let keypair_path = format!("target/deploy/{}-keypair.json", program.lib_name); + std::fs::remove_file(keypair_path)?; + println!("Deploying {}...", binary_path); let exit = std::process::Command::new("solana") + .arg("program") .arg("deploy") - .arg(&binary_path) .arg("--url") .arg(url) .arg("--keypair") .arg(keypair) + .arg(&binary_path) .output() .expect("Must deploy"); if !exit.status.success() { diff --git a/examples/lockup/migrations/deploy.js b/examples/lockup/migrations/deploy.js index 4e05bdd9b..8a51683e3 100644 --- a/examples/lockup/migrations/deploy.js +++ b/examples/lockup/migrations/deploy.js @@ -90,15 +90,15 @@ async function genesis(provider) { ) { return { srm: { - withdrawalTimelock: 60, - stakeRate: 1000 * 10 ** 6, - rewardQLen: 100, + withdrawalTimelock: 60 * 60 * 24 * 7, // 1 week. + stakeRate: 500 * 10 ** 6, // 500 SRM. + rewardQLen: 150, mint: "SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt", }, msrm: { - withdrawalTimelock: 45, + withdrawalTimelock: 60 * 60 * 24 * 7, // 1 week. stakeRate: 1, - rewardQLen: 100, + rewardQLen: 150, mint: "MSRMcoVyrFxnSgo5uXwone5SKcGhT1KEJMFEkMEWf9L", }, }; @@ -117,15 +117,15 @@ async function genesis(provider) { ); return { token1: { - withdrawalTimelock: 60, - stakeRate: 2 * 10 ** 6, - rewardQLen: 100, + withdrawalTimelock: 60 * 60 * 24 * 7, + stakeRate: 1000 * 10 ** 6, + rewardQLen: 150, mint: token1Mint.toString(), }, token2: { - withdrawalTimelock: 45, + withdrawalTimelock: 60 * 60 * 24 * 7, stakeRate: 1, - rewardQLen: 100, + rewardQLen: 150, mint: token2Mint.toString(), }, }; diff --git a/examples/lockup/programs/lockup/src/lib.rs b/examples/lockup/programs/lockup/src/lib.rs index e7ddfc29d..e7feb8e4d 100644 --- a/examples/lockup/programs/lockup/src/lib.rs +++ b/examples/lockup/programs/lockup/src/lib.rs @@ -23,7 +23,7 @@ pub mod lockup { } impl Lockup { - pub const WHITELIST_SIZE: usize = 5; + pub const WHITELIST_SIZE: usize = 10; pub fn new(ctx: Context) -> Result { let mut whitelist = vec![]; @@ -111,7 +111,7 @@ pub mod lockup { ctx.accounts.clock.unix_timestamp, ) { - return Err(ErrorCode::InsufficienWithdrawalBalance.into()); + return Err(ErrorCode::InsufficientWithdrawalBalance.into()); } // Transfer funds out. @@ -348,7 +348,7 @@ pub enum ErrorCode { #[msg("Vault amount must be zero.")] InvalidVaultAmount, #[msg("Insufficient withdrawal balance.")] - InsufficienWithdrawalBalance, + InsufficientWithdrawalBalance, #[msg("Whitelist is full")] WhitelistFull, #[msg("Whitelist entry already exists")] diff --git a/examples/lockup/tests/lockup.js b/examples/lockup/tests/lockup.js index ddd4573cb..f455f8243 100644 --- a/examples/lockup/tests/lockup.js +++ b/examples/lockup/tests/lockup.js @@ -1,5 +1,5 @@ const assert = require("assert"); -const anchor = require('@project-serum/anchor'); +const anchor = require("@project-serum/anchor"); const serumCmn = require("@project-serum/common"); const TokenInstructions = require("@project-serum/serum").TokenInstructions; const utils = require("./utils"); @@ -15,6 +15,7 @@ describe("Lockup and Registry", () => { const registry = anchor.workspace.Registry; let lockupAddress = null; + const WHITELIST_SIZE = 10; let mint = null; let god = null; @@ -39,7 +40,7 @@ describe("Lockup and Registry", () => { const lockupAccount = await lockup.state(); assert.ok(lockupAccount.authority.equals(provider.wallet.publicKey)); - assert.ok(lockupAccount.whitelist.length === 5); + assert.ok(lockupAccount.whitelist.length === WHITELIST_SIZE); lockupAccount.whitelist.forEach((e) => { assert.ok(e.programId.equals(new anchor.web3.PublicKey())); }); @@ -76,11 +77,7 @@ describe("Lockup and Registry", () => { assert.ok(lockupAccount.authority.equals(provider.wallet.publicKey)); }); - let e0 = null; - let e1 = null; - let e2 = null; - let e3 = null; - let e4 = null; + const entries = []; it("Adds to the whitelist", async () => { const generateEntry = async () => { @@ -89,36 +86,34 @@ describe("Lockup and Registry", () => { programId, }; }; - e0 = await generateEntry(); - e1 = await generateEntry(); - e2 = await generateEntry(); - e3 = await generateEntry(); - e4 = await generateEntry(); - const e5 = await generateEntry(); + + for (let k = 0; k < WHITELIST_SIZE; k += 1) { + entries.push(await generateEntry()); + } const accounts = { authority: provider.wallet.publicKey, }; - await lockup.state.rpc.whitelistAdd(e0, { accounts }); + await lockup.state.rpc.whitelistAdd(entries[0], { accounts }); let lockupAccount = await lockup.state(); assert.ok(lockupAccount.whitelist.length === 1); - assert.deepEqual(lockupAccount.whitelist, [e0]); + assert.deepEqual(lockupAccount.whitelist, [entries[0]]); - await lockup.state.rpc.whitelistAdd(e1, { accounts }); - await lockup.state.rpc.whitelistAdd(e2, { accounts }); - await lockup.state.rpc.whitelistAdd(e3, { accounts }); - await lockup.state.rpc.whitelistAdd(e4, { accounts }); + for (let k = 1; k < WHITELIST_SIZE; k += 1) { + await lockup.state.rpc.whitelistAdd(entries[k], { accounts }); + } lockupAccount = await lockup.state(); - assert.deepEqual(lockupAccount.whitelist, [e0, e1, e2, e3, e4]); + assert.deepEqual(lockupAccount.whitelist, entries); await assert.rejects( async () => { - await lockup.state.rpc.whitelistAdd(e5, { accounts }); + const e = await generateEntry(); + await lockup.state.rpc.whitelistAdd(e, { accounts }); }, (err) => { assert.equal(err.code, 108); @@ -129,13 +124,13 @@ describe("Lockup and Registry", () => { }); it("Removes from the whitelist", async () => { - await lockup.state.rpc.whitelistDelete(e0, { + await lockup.state.rpc.whitelistDelete(entries[0], { accounts: { authority: provider.wallet.publicKey, }, }); let lockupAccount = await lockup.state(); - assert.deepEqual(lockupAccount.whitelist, [e1, e2, e3, e4]); + assert.deepEqual(lockupAccount.whitelist, entries.slice(1)); }); const vesting = new anchor.web3.Account(); @@ -264,7 +259,7 @@ describe("Lockup and Registry", () => { const rewardQ = new anchor.web3.Account(); const withdrawalTimelock = new anchor.BN(4); const stakeRate = new anchor.BN(2); - const rewardQLen = 100; + const rewardQLen = 170; let registrarAccount = null; let registrarSigner = null; let nonce = null;