Skip to content

Commit

Permalink
feat: add contract testing without nodes (#685)
Browse files Browse the repository at this point in the history
* implement contract sign() with yield/resume

* fix: lcoal state clearing not successful, and refactor signature_responded to return Error types instead of anyhow

* clippy

* Added contract testing without node setup

* Some cleanup

* Updated tests with more cases

* Updated contract to have threshold check for init

* Fix fmt, clippy

---------

Co-authored-by: Xiangyi Zheng <xiangyi@near.org>
  • Loading branch information
ChaoticTempest and ppca authored Jul 17, 2024
1 parent f801f31 commit 7277413
Show file tree
Hide file tree
Showing 6 changed files with 374 additions and 24 deletions.
15 changes: 10 additions & 5 deletions chain-signatures/Cargo.lock

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

13 changes: 11 additions & 2 deletions chain-signatures/contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ crypto-shared = { path = "../crypto-shared" }
near-gas = { version = "0.2.5", features = ["serde", "borsh", "schemars"] }

[dev-dependencies]
near-workspaces = { git = "https://github.com/near/near-workspaces-rs", branch = "node/1.40" }
anyhow = "1"
rand = "0.8"
tokio = { version = "1", features = ["full"] }
anyhow = "1.0.44"

# crypto dependencies
ecdsa = { version = "0.16.9", features = ["digest", "hazmat"] }
signature = "2.2.0"
digest = "0.10.7"

# near dependencies
near-crypto = "0.23.0"
near-workspaces = { git = "https://github.com/near/near-workspaces-rs", branch = "node/1.40" }
10 changes: 9 additions & 1 deletion chain-signatures/contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,16 @@ impl VersionedMpcContract {
#[init]
pub fn init(threshold: usize, candidates: BTreeMap<AccountId, CandidateInfo>) -> Self {
log!(
"init: signer={}, treshhold={}, candidates={}",
"init: signer={}, threshold={}, candidates={}",
env::signer_account_id(),
threshold,
serde_json::to_string(&candidates).unwrap()
);

if threshold > candidates.len() {
env::panic_str("threshold cannot be greater than the number of candidates");
}

Self::V0(MpcContract::init(threshold, candidates))
}

Expand All @@ -643,6 +647,10 @@ impl VersionedMpcContract {
public_key
);

if threshold > participants.len() {
env::panic_str("threshold cannot be greater than the number of participants");
}

Self::V0(MpcContract {
protocol_state: ProtocolContractState::Running(RunningContractState {
epoch,
Expand Down
Loading

0 comments on commit 7277413

Please sign in to comment.