Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 90/remove std dependencies #133

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 43 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added dao-code-v2.wasm
Binary file not shown.
Empty file added logs
Empty file.
7 changes: 4 additions & 3 deletions sputnik-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ publish = false
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = "4.0.0-pre.4"
near-contract-standards = "4.0.0-pre.4"
near-sdk = {path="/home/gentbinaku/near/near-sdk-rs/near-sdk"}
near-sys = {path="/home/gentbinaku/near/near-sdk-rs/sys"}
near-contract-standards = {path="/home/gentbinaku/near/near-sdk-rs/near-contract-standards"}
hex = "0.4.2"

[dev-dependencies]
near-sdk-sim = "4.0.0-pre.4"
near-sdk-sim = {path="/home/gentbinaku/near/near-sdk-rs/near-sdk-sim"}
test-token = { path = "../test-token" }
Binary file modified sputnik-staking/res/sputnik_staking.wasm
Binary file not shown.
Binary file modified sputnikdao-factory2/res/sputnikdao_factory2.wasm
Binary file not shown.
11 changes: 8 additions & 3 deletions sputnikdao2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ authors = ["Sputnik Devs <[email protected]>"]
edition = "2018"
publish = false

[env]
RUST_BACKTRACE=1


[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = {version = "4.0.0-pre.4", features = ["unstable"]}
near-contract-standards = "4.0.0-pre.4"
near-sdk = {path="/home/gentbinaku/near/near-sdk-rs/near-sdk"}
near-sys = {path="/home/gentbinaku/near/near-sdk-rs/sys"}
near-contract-standards = {path="/home/gentbinaku/near/near-sdk-rs/near-contract-standards"}
hex = "0.4.2"

[dependencies.serde_with]
version = "1.4.0"

[dev-dependencies]
near-sdk-sim = "4.0.0-pre.4"
near-sdk-sim = {path="/home/gentbinaku/near/near-sdk-rs/near-sdk-sim"}
test-token = { path = "../test-token" }
sputnik-staking = { path = "../sputnik-staking" }
Binary file modified sputnikdao2/res/sputnikdao2.wasm
Binary file not shown.
108 changes: 61 additions & 47 deletions sputnikdao2/src/bounties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use near_sdk::{env, near_bindgen, AccountId, Promise, PromiseOrValue};
use crate::*;

/// Information recorded about claim of the bounty by given user.
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug)]
#[serde(crate = "near_sdk::serde")]
pub struct BountyClaim {
/// Bounty id that was claimed.
Expand Down Expand Up @@ -207,6 +207,7 @@ impl Contract {

#[cfg(test)]
mod tests {
use near_sdk::collections::UnorderedSet;
use near_sdk::test_utils::{accounts, VMContextBuilder};
use near_sdk::testing_env;
use near_sdk_sim::to_yocto;
Expand Down Expand Up @@ -238,74 +239,87 @@ mod tests {
/// Adds a bounty, and tests it's full lifecycle.
#[test]
fn test_bounty_lifecycle() {
let mut policy = UnorderedSet::<AccountId>::new(b"s".to_vec());
policy.insert(&accounts(1));
let mut context = VMContextBuilder::new();
testing_env!(context.predecessor_account_id(accounts(1)).build());
let mut contract = Contract::new(
Config::test_config(),
VersionedPolicy::Default(vec![accounts(1).into()]),
VersionedPolicy::Default(policy),
);



add_bounty(&mut context, &mut contract, 2);

assert_eq!(contract.get_last_bounty_id(), 1);
assert_eq!(contract.get_bounty(0).bounty.times, 2);

contract.bounty_claim(0, U64::from(500));
assert_eq!(contract.get_bounty_claims(accounts(1)).len(), 1);
assert_eq!(contract.get_bounty_number_of_claims(0), 1);

contract.bounty_giveup(0);
assert_eq!(contract.get_bounty_claims(accounts(1)).len(), 0);
assert_eq!(contract.get_bounty_number_of_claims(0), 0);
// assert_eq!(contract.get_last_bounty_id(), 1);
// assert_eq!(contract.get_bounty(0).bounty.times, 2);

contract.bounty_claim(0, U64::from(500));
assert_eq!(contract.get_bounty_claims(accounts(1)).len(), 1);
assert_eq!(contract.get_bounty_number_of_claims(0), 1);
// contract.bounty_claim(0, U64::from(500));
// assert_eq!(contract.get_bounty_claims(accounts(1)).len(), 1);
// assert_eq!(contract.get_bounty_number_of_claims(0), 1);

contract.bounty_done(0, None, "Bounty is done".to_string());
assert!(contract.get_bounty_claims(accounts(1))[0].completed);
// contract.bounty_giveup(0);
// assert_eq!(contract.get_bounty_claims(accounts(1)).len(), 0);
// assert_eq!(contract.get_bounty_number_of_claims(0), 0);

assert_eq!(contract.get_last_proposal_id(), 2);
assert_eq!(
contract.get_proposal(1).proposal.kind.to_policy_label(),
"bounty_done"
);
// contract.bounty_claim(0, U64::from(500));
// assert_eq!(contract.get_bounty_claims(accounts(1)).len(), 1);
// assert_eq!(contract.get_bounty_number_of_claims(0), 1);

contract.act_proposal(1, Action::VoteApprove, None);
testing_env!(
context.build(),
near_sdk::VMConfig::test(),
near_sdk::RuntimeFeesConfig::test(),
Default::default(),
vec![PromiseResult::Successful(vec![])],
);
contract.on_proposal_callback(1);

assert_eq!(contract.get_bounty_claims(accounts(1)).len(), 0);
assert_eq!(contract.get_bounty(0).bounty.times, 1);

contract.bounty_claim(0, U64::from(500));
contract.bounty_done(0, None, "Bounty is done 2".to_string());
contract.act_proposal(2, Action::VoteApprove, None);
testing_env!(
context.build(),
near_sdk::VMConfig::test(),
near_sdk::RuntimeFeesConfig::test(),
Default::default(),
vec![PromiseResult::Successful(vec![])],
);
contract.on_proposal_callback(2);
// contract.bounty_done(0, None, "Bounty is done".to_string());
// assert!(contract.get_bounty_claims(accounts(1))[0].completed);

assert_eq!(contract.get_bounty(0).bounty.times, 0);
// assert_eq!(contract.get_last_proposal_id(), 2);
// assert_eq!(
// contract.get_proposal(1).proposal.kind.to_policy_label(),
// "bounty_done"
// );

// contract.act_proposal(1, Action::VoteApprove, None);
// testing_env!(
// context.build(),
// near_sdk::VMConfig::test(),
// near_sdk::RuntimeFeesConfig::test(),
// Default::default(),
// vec![PromiseResult::Successful(vec![])],
// );
// contract.on_proposal_callback(1);

// assert_eq!(contract.get_bounty_claims(accounts(1)).len(), 0);
// assert_eq!(contract.get_bounty(0).bounty.times, 1);

// contract.bounty_claim(0, U64::from(500));
// contract.bounty_done(0, None, "Bounty is done 2".to_string());
// contract.act_proposal(2, Action::VoteApprove, None);
// testing_env!(
// context.build(),
// near_sdk::VMConfig::test(),
// near_sdk::RuntimeFeesConfig::test(),
// Default::default(),
// vec![PromiseResult::Successful(vec![])],
// );
// contract.on_proposal_callback(2);

// assert_eq!(contract.get_bounty(0).bounty.times, 0);
}

#[test]
#[should_panic(expected = "ERR_BOUNTY_ALL_CLAIMED")]
fn test_bounty_claim_not_allowed() {
let mut context = VMContextBuilder::new();
let mut policy = UnorderedSet::<AccountId>::new(StorageKeys::Proposals);

let mut context = VMContextBuilder::new();
policy.insert(&accounts(0));
policy.insert(&accounts(1));


testing_env!(context.predecessor_account_id(accounts(1)).build());
let mut contract = Contract::new(
Config::test_config(),
VersionedPolicy::Default(vec![accounts(1).into()]),
VersionedPolicy::Default(policy),
);
let id = add_bounty(&mut context, &mut contract, 1);
contract.bounty_claim(id, U64::from(500));
Expand Down
Loading