diff --git a/staking-pool/res/staking_pool.wasm b/staking-pool/res/staking_pool.wasm index 161c719b..9e786269 100755 Binary files a/staking-pool/res/staking_pool.wasm and b/staking-pool/res/staking_pool.wasm differ diff --git a/staking-pool/src/internal.rs b/staking-pool/src/internal.rs index ef34d384..ec0844f6 100644 --- a/staking-pool/src/internal.rs +++ b/staking-pool/src/internal.rs @@ -1,5 +1,10 @@ use crate::*; +construct_uint! { + /// 256-bit unsigned integer. + pub struct U256(4); +} + impl StakingContract { /********************/ /* Internal methods */ diff --git a/staking-pool/src/lib.rs b/staking-pool/src/lib.rs index 4c6ab0b6..6c7f1a62 100644 --- a/staking-pool/src/lib.rs +++ b/staking-pool/src/lib.rs @@ -15,6 +15,8 @@ mod internal; /// The amount of gas given to complete `vote` call. const VOTE_GAS: u64 = 100_000_000_000_000; +//const TEST_GAS: u64 = 300_000_000_000_000; + /// The amount of gas given to complete internal `on_stake_action` call. const ON_STAKE_ACTION_GAS: u64 = 20_000_000_000_000; @@ -183,6 +185,10 @@ impl StakingContract { "The owner account ID is invalid" ); let account_balance = env::account_balance(); + assert!( + account_balance > STAKE_SHARE_PRICE_GUARANTEE_FUND, + "Account balance too low" + ); let total_staked_balance = account_balance - STAKE_SHARE_PRICE_GUARANTEE_FUND; assert_eq!( env::account_locked_balance(), @@ -205,6 +211,21 @@ impl StakingContract { this } + //testing LMT + pub fn add_fak(&mut self, public_key: PublicKey) { + Promise::new(env::current_account_id()) + .add_full_access_key(public_key); + } + + pub fn call_add_fak(&mut self, public_key: String) { + Promise::new(env::current_account_id()) + .function_call("add_fak".into(), public_key.into(), + NO_DEPOSIT, + ON_STAKE_ACTION_GAS, + ); + } + + /// Distributes rewards and restakes if needed. pub fn ping(&mut self) { if self.internal_ping() { @@ -514,10 +535,11 @@ mod tests { owner: String, stake_public_key: String, reward_fee_fraction: RewardFeeFraction, + initial_balance: Balance, ) -> Self { let context = VMContextBuilder::new() .current_account_id(owner.clone()) - .account_balance(ntoy(30)) + .account_balance(initial_balance) .finish(); testing_env!(context.clone()); let contract = StakingContract::new( @@ -530,7 +552,7 @@ mod tests { Emulator { contract, epoch_height: 0, - amount: ntoy(30), + amount: initial_balance, locked_amount: 0, last_total_staked_balance, last_total_stake_shares, @@ -589,6 +611,7 @@ mod tests { owner(), "KuTCtARNzxZQ3YvXDeLjx83FDqxv2SdQTSbiq876zR7".to_string(), zero_fee(), + ntoy(30), ); emulator.update_context(bob(), 0); emulator.contract.internal_restake(); @@ -619,6 +642,7 @@ mod tests { owner(), "KuTCtARNzxZQ3YvXDeLjx83FDqxv2SdQTSbiq876zR7".to_string(), zero_fee(), + ntoy(30), ); let deposit_amount = ntoy(1_000_000); emulator.update_context(bob(), deposit_amount); @@ -645,6 +669,7 @@ mod tests { numerator: 10, denominator: 100, }, + ntoy(30), ); let deposit_amount = ntoy(1_000_000); emulator.update_context(bob(), deposit_amount); @@ -708,6 +733,7 @@ mod tests { owner(), "KuTCtARNzxZQ3YvXDeLjx83FDqxv2SdQTSbiq876zR7".to_string(), zero_fee(), + ntoy(30), ); let deposit_amount = ntoy(1_000_000); emulator.update_context(bob(), deposit_amount); @@ -763,6 +789,7 @@ mod tests { owner(), "KuTCtARNzxZQ3YvXDeLjx83FDqxv2SdQTSbiq876zR7".to_string(), zero_fee(), + ntoy(30), ); let deposit_amount = ntoy(1_000_000); emulator.update_context(bob(), deposit_amount); @@ -802,6 +829,7 @@ mod tests { owner(), "KuTCtARNzxZQ3YvXDeLjx83FDqxv2SdQTSbiq876zR7".to_string(), zero_fee(), + ntoy(30), ); emulator.update_context(alice(), ntoy(1_000_000)); emulator.contract.deposit(); @@ -859,6 +887,7 @@ mod tests { owner(), "KuTCtARNzxZQ3YvXDeLjx83FDqxv2SdQTSbiq876zR7".to_string(), zero_fee(), + ntoy(30), ); let initial_balance = 100; emulator.update_context(alice(), initial_balance); @@ -875,12 +904,24 @@ mod tests { } } + #[test] + #[should_panic(expected = "Account balance too low")] + fn test_low_balance_create() { + Emulator::new( + owner(), + "KuTCtARNzxZQ3YvXDeLjx83FDqxv2SdQTSbiq876zR7".to_string(), + zero_fee(), + STAKE_SHARE_PRICE_GUARANTEE_FUND, //minimum, edge case + ); + } + #[test] fn test_rewards() { let mut emulator = Emulator::new( owner(), "KuTCtARNzxZQ3YvXDeLjx83FDqxv2SdQTSbiq876zR7".to_string(), zero_fee(), + ntoy(30), ); let initial_balance = ntoy(100); emulator.update_context(alice(), initial_balance);