diff --git a/.github/workflows/tests-advanced-ts.yml b/.github/workflows/tests-advanced-ts.yml index 0328685..31a8a3a 100644 --- a/.github/workflows/tests-advanced-ts.yml +++ b/.github/workflows/tests-advanced-ts.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: - node-version: "18" + node-version: "20" - name: Install and test modules run: | cd ./contract-advanced-ts diff --git a/.github/workflows/tests-simple-ts.yml b/.github/workflows/tests-simple-ts.yml index 4fb2c6c..d3d83c8 100644 --- a/.github/workflows/tests-simple-ts.yml +++ b/.github/workflows/tests-simple-ts.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: - node-version: "18" + node-version: "20" - name: Install and test modules run: | cd ./contract-simple-ts diff --git a/contract-advanced-rs/.cargo/config b/contract-advanced-rs/.cargo/config deleted file mode 100644 index 58910a4..0000000 --- a/contract-advanced-rs/.cargo/config +++ /dev/null @@ -1,2 +0,0 @@ -[build] -rustflags = ["-C", "link-args=-s"] diff --git a/contract-advanced-rs/Cargo.toml b/contract-advanced-rs/Cargo.toml index d67c76d..ab4eeba 100644 --- a/contract-advanced-rs/Cargo.toml +++ b/contract-advanced-rs/Cargo.toml @@ -9,24 +9,12 @@ crate-type = ["cdylib", "rlib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -near-sdk = "5.4.0" +near-sdk = "5.6.0" +near-contract-standards = "5.6.0" schemars = "0.8.16" [dev-dependencies] -near-sdk = { version = "5.4.0", features = ["unit-testing"] } -near-workspaces = { version = "0.11.0", features = ["unstable"] } +near-sdk = { version = "5.6.0", features = ["unit-testing"] } +near-workspaces = { version = "0.15.0", features = ["unstable"] } tokio = { version = "1.12.0", features = ["full"] } serde_json = "1" - -[profile.release] -codegen-units = 1 -# Tell `rustc` to optimize for small code size. -opt-level = "z" -lto = true -debug = false -panic = "abort" -# Opt into extra safety checks on arithmetic operations https://stackoverflow.com/a/64136471/249801 -overflow-checks = true - -[workspace] -members = [] diff --git a/contract-advanced-rs/tests/external-contracts/counter.wasm b/contract-advanced-rs/tests/contracts/counter.wasm similarity index 100% rename from contract-advanced-rs/tests/external-contracts/counter.wasm rename to contract-advanced-rs/tests/contracts/counter.wasm diff --git a/contract-advanced-rs/tests/external-contracts/guest-book.wasm b/contract-advanced-rs/tests/contracts/guest-book.wasm similarity index 100% rename from contract-advanced-rs/tests/external-contracts/guest-book.wasm rename to contract-advanced-rs/tests/contracts/guest-book.wasm diff --git a/contract-advanced-rs/tests/contracts/hello-near/Cargo.toml b/contract-advanced-rs/tests/contracts/hello-near/Cargo.toml new file mode 100644 index 0000000..eaecaac --- /dev/null +++ b/contract-advanced-rs/tests/contracts/hello-near/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "hello-near" +description = "Hello Near Example" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +near-sdk = "5.6.0" + +[dev-dependencies] +near-sdk = { version = "5.6.0", features = ["unit-testing"] } +near-workspaces = { version = "0.15.0", features = ["unstable"] } +tokio = { version = "1.12.0", features = ["full"] } +serde_json = "1" diff --git a/contract-advanced-rs/tests/contracts/hello-near/src/lib.rs b/contract-advanced-rs/tests/contracts/hello-near/src/lib.rs new file mode 100644 index 0000000..188be11 --- /dev/null +++ b/contract-advanced-rs/tests/contracts/hello-near/src/lib.rs @@ -0,0 +1,55 @@ +// Find all our documentation at https://docs.near.org +use near_sdk::{log, near}; + +// Define the contract structure +#[near(contract_state)] +pub struct Contract { + greeting: String, +} + +// Define the default, which automatically initializes the contract +impl Default for Contract { + fn default() -> Self { + Self { + greeting: "Hello".to_string(), + } + } +} + +// Implement the contract structure +#[near] +impl Contract { + // Public method - returns the greeting saved, defaulting to DEFAULT_GREETING + pub fn get_greeting(&self) -> String { + self.greeting.clone() + } + + // Public method - accepts a greeting, such as "howdy", and records it + pub fn set_greeting(&mut self, greeting: String) { + log!("Saving greeting: {}", greeting); + self.greeting = greeting; + } +} + +/* + * The rest of this file holds the inline tests for the code above + * Learn more about Rust tests: https://doc.rust-lang.org/book/ch11-01-writing-tests.html + */ +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn get_default_greeting() { + let contract = Contract::default(); + // this test did not call set_greeting so should return the default "Hello" greeting + assert_eq!(contract.get_greeting(), "Hello"); + } + + #[test] + fn set_then_get_greeting() { + let mut contract = Contract::default(); + contract.set_greeting("howdy".to_string()); + assert_eq!(contract.get_greeting(), "howdy"); + } +} diff --git a/contract-advanced-rs/tests/external-contracts/hello-near.wasm b/contract-advanced-rs/tests/external-contracts/hello-near.wasm deleted file mode 100755 index c568536..0000000 Binary files a/contract-advanced-rs/tests/external-contracts/hello-near.wasm and /dev/null differ diff --git a/contract-advanced-rs/tests/tests.rs b/contract-advanced-rs/tests/tests.rs index 7a1e3c5..b500498 100644 --- a/contract-advanced-rs/tests/tests.rs +++ b/contract-advanced-rs/tests/tests.rs @@ -1,24 +1,25 @@ -use std::string::String; -use serde_json::json; -use near_workspaces::{types::NearToken, Account, Contract}; use near_sdk::near; - +use near_workspaces::{types::NearToken, Account, Contract}; +use serde_json::json; +use std::string::String; + #[tokio::test] async fn main() -> Result<(), Box> { let worker = near_workspaces::sandbox().await?; // Deploy hello contract - let hello_contract_wasm = std::fs::read("./tests/external-contracts/hello-near.wasm")?; + let hello_contract_wasm = + near_workspaces::compile_project("./tests/contracts/hello-near").await?; let hello_contract = worker.dev_deploy(&hello_contract_wasm).await?; // Deploy guest-book contract - let guest_book_contract_wasm = std::fs::read("./tests/external-contracts/guest-book.wasm")?; + let guest_book_contract_wasm = std::fs::read("./tests/contracts/guest-book.wasm")?; let guest_book_contract = worker.dev_deploy(&guest_book_contract_wasm).await?; // Deploy counter contract - let counter_contract_wasm = std::fs::read("./tests/external-contracts/counter.wasm")?; + let counter_contract_wasm = std::fs::read("./tests/contracts/counter.wasm")?; let counter_contract = worker.dev_deploy(&counter_contract_wasm).await?; // Deploy contract for testing let contract_wasm = near_workspaces::compile_project("./").await?; let contract = worker.dev_deploy(&contract_wasm).await?; - + // Create accounts let account = worker.dev_create_account().await?; let alice = account @@ -39,9 +40,16 @@ async fn main() -> Result<(), Box> { .transact() .await? .into_result()?; - + // Begin tests - test_multiple_contracts(&alice, &contract, &hello_contract, &guest_book_contract, &counter_contract).await?; + test_multiple_contracts( + &alice, + &contract, + &hello_contract, + &guest_book_contract, + &counter_contract, + ) + .await?; test_similar_contracts(&alice, &contract).await?; test_batch_actions(&alice, &contract).await?; Ok(()) @@ -52,7 +60,7 @@ async fn test_multiple_contracts( contract: &Contract, hello_contract: &Contract, guest_book_contract: &Contract, - counter_contract: &Contract + counter_contract: &Contract, ) -> Result<(), Box> { #[derive(Debug, PartialEq)] #[near(serializers = [json])] @@ -96,7 +104,7 @@ async fn test_multiple_contracts( .transact() .await? .json()?; - + assert_eq!(result.0, "Howdy".to_string()); assert_eq!(result.1, -1); assert_eq!(result.2, expected_messages); @@ -104,40 +112,40 @@ async fn test_multiple_contracts( } async fn test_similar_contracts( - user: &Account, - contract: &Contract + user: &Account, + contract: &Contract, ) -> Result<(), Box> { - let expected: Vec = vec![ - "hi".parse().unwrap(), - "howdy".parse().unwrap(), - "bye".parse().unwrap() - ]; - - let result: Vec = user - .call(contract.id(), "similar_contracts") - .args_json(json!({})) - .max_gas() - .transact() - .await? - .json()?; - - assert_eq!(result, expected); - Ok(()) + let expected: Vec = vec![ + "hi".parse().unwrap(), + "howdy".parse().unwrap(), + "bye".parse().unwrap(), + ]; + + let result: Vec = user + .call(contract.id(), "similar_contracts") + .args_json(json!({})) + .max_gas() + .transact() + .await? + .json()?; + + assert_eq!(result, expected); + Ok(()) } async fn test_batch_actions( - user: &Account, - contract: &Contract + user: &Account, + contract: &Contract, ) -> Result<(), Box> { - let expected: String = "bye".parse().unwrap(); - let result: String = user - .call(contract.id(), "batch_actions") - .args_json(json!({})) - .max_gas() - .transact() - .await? - .json()?; - - assert_eq!(result, expected); - Ok(()) -} \ No newline at end of file + let expected: String = "bye".parse().unwrap(); + let result: String = user + .call(contract.id(), "batch_actions") + .args_json(json!({})) + .max_gas() + .transact() + .await? + .json()?; + + assert_eq!(result, expected); + Ok(()) +} diff --git a/contract-advanced-ts/package.json b/contract-advanced-ts/package.json index d3eed25..d4354b7 100644 --- a/contract-advanced-ts/package.json +++ b/contract-advanced-ts/package.json @@ -8,13 +8,13 @@ "test": "$npm_execpath build && ava -- ./build/cross_contract.wasm" }, "dependencies": { - "near-cli": "^4.0.10", - "near-sdk-js": "1.0.0" + "near-cli": "^4.0.13", + "near-sdk-js": "2.0.0" }, "devDependencies": { "@ava/typescript": "^4.1.0", "ava": "^6.1.2", - "near-workspaces": "^3.5.0", + "near-workspaces": "^4.0.0", "ts-morph": "^22.0.0", "ts-node": "^10.9.2", "tsimp": "^2.0.11", diff --git a/contract-simple-rs/.cargo/config b/contract-simple-rs/.cargo/config deleted file mode 100644 index 58910a4..0000000 --- a/contract-simple-rs/.cargo/config +++ /dev/null @@ -1,2 +0,0 @@ -[build] -rustflags = ["-C", "link-args=-s"] diff --git a/contract-simple-rs/Cargo.toml b/contract-simple-rs/Cargo.toml index b8e038e..f86bcad 100644 --- a/contract-simple-rs/Cargo.toml +++ b/contract-simple-rs/Cargo.toml @@ -5,27 +5,15 @@ authors = ["Near Inc "] edition = "2021" [lib] -crate-type = ["cdylib", "rlib"] +crate-type = ["cdylib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -near-sdk = "5.4.0" +near-sdk = "5.6.0" +near-contract-standards = "5.6.0" [dev-dependencies] -near-sdk = { version = "5.4.0", features = ["unit-testing"] } -near-workspaces = { version = "0.11.0", features = ["unstable"] } +near-sdk = { version = "5.6.0", features = ["unit-testing"] } +near-workspaces = { version = "0.15.0", features = ["unstable"] } tokio = { version = "1.12.0", features = ["full"] } -serde_json = "1" - -[profile.release] -codegen-units = 1 -# Tell `rustc` to optimize for small code size. -opt-level = "z" -lto = true -debug = false -panic = "abort" -# Opt into extra safety checks on arithmetic operations https://stackoverflow.com/a/64136471/249801 -overflow-checks = true - -[workspace] -members = [] +serde_json = "1" \ No newline at end of file diff --git a/contract-simple-rs/src/external.rs b/contract-simple-rs/src/external_contract.rs similarity index 63% rename from contract-simple-rs/src/external.rs rename to contract-simple-rs/src/external_contract.rs index 7890b4a..1cc88f9 100644 --- a/contract-simple-rs/src/external.rs +++ b/contract-simple-rs/src/external_contract.rs @@ -1,9 +1,5 @@ -// Find all our documentation at https://docs.near.org use near_sdk::ext_contract; -pub const NO_DEPOSIT: u128 = 0; -pub const XCC_SUCCESS: u64 = 1; - // Validator interface, for cross-contract calls #[ext_contract(hello_near)] trait HelloNear { diff --git a/contract-simple-rs/src/high_level.rs b/contract-simple-rs/src/high_level.rs new file mode 100644 index 0000000..89b5f1c --- /dev/null +++ b/contract-simple-rs/src/high_level.rs @@ -0,0 +1,67 @@ +// Find all our documentation at https://docs.near.org/ +use near_sdk::{env, log, near, Promise, PromiseError}; + +use crate::{hello_near, Contract, ContractExt, FIVE_TGAS}; + +#[near] +impl Contract { + // Public - query external greeting + pub fn hl_query_greeting(&self) -> Promise { + // Create a promise to call HelloNEAR.get_greeting() + let promise = hello_near::ext(self.hello_account.clone()) + .with_static_gas(FIVE_TGAS) + .get_greeting(); + + promise.then( + // Create a promise to callback query_greeting_callback + Self::ext(env::current_account_id()) + .with_static_gas(FIVE_TGAS) + .hl_query_greeting_callback(), + ) + } + + #[private] // Public - but only callable by env::current_account_id() + pub fn hl_query_greeting_callback( + &self, + #[callback_result] call_result: Result, + ) -> String { + // Check if the promise succeeded by calling the method outlined in external.rs + if call_result.is_err() { + log!("There was an error contacting Hello NEAR"); + return "".to_string(); + } + + // Return the greeting + let greeting: String = call_result.unwrap(); + greeting + } + + // Public - change external greeting + pub fn hl_change_greeting(&mut self, new_greeting: String) -> Promise { + // Create a promise to call HelloNEAR.set_greeting(message:string) + hello_near::ext(self.hello_account.clone()) + .with_static_gas(FIVE_TGAS) + .set_greeting(new_greeting) + .then( + // Create a callback change_greeting_callback + Self::ext(env::current_account_id()) + .with_static_gas(FIVE_TGAS) + .hl_change_greeting_callback(), + ) + } + + #[private] + pub fn hl_change_greeting_callback( + &mut self, + #[callback_result] call_result: Result<(), PromiseError>, + ) -> bool { + // Return whether or not the promise succeeded using the method outlined in external.rs + if call_result.is_err() { + env::log_str("set_greeting failed..."); + false + } else { + env::log_str("set_greeting was successful!"); + true + } + } +} diff --git a/contract-simple-rs/src/lib.rs b/contract-simple-rs/src/lib.rs index 481504e..fd07471 100644 --- a/contract-simple-rs/src/lib.rs +++ b/contract-simple-rs/src/lib.rs @@ -1,8 +1,16 @@ // Find all our documentation at https://docs.near.org -use near_sdk::{env, log, near, AccountId, Gas, PanicOnDefault, Promise, PromiseError}; +use near_sdk::{env, near, AccountId, Gas, NearToken, PanicOnDefault}; -pub mod external; -pub use crate::external::*; +pub mod external_contract; +pub use crate::external_contract::*; + +pub mod high_level; +pub mod low_level; + +const NO_ARGS: Vec = vec![]; +const NO_DEPOSIT: NearToken = NearToken::from_near(0); +const FIVE_TGAS: Gas = Gas::from_tgas(5); +const TEN_TGAS: Gas = Gas::from_tgas(10); #[near(contract_state)] #[derive(PanicOnDefault)] @@ -18,66 +26,6 @@ impl Contract { assert!(!env::state_exists(), "Already initialized"); Self { hello_account } } - - // Public - query external greeting - pub fn query_greeting(&self) -> Promise { - // Create a promise to call HelloNEAR.get_greeting() - let promise = hello_near::ext(self.hello_account.clone()) - .with_static_gas(Gas::from_tgas(5)) - .get_greeting(); - - return promise.then( - // Create a promise to callback query_greeting_callback - Self::ext(env::current_account_id()) - .with_static_gas(Gas::from_tgas(5)) - .query_greeting_callback(), - ); - } - - #[private] // Public - but only callable by env::current_account_id() - pub fn query_greeting_callback( - &self, - #[callback_result] call_result: Result, - ) -> String { - // Check if the promise succeeded by calling the method outlined in external.rs - if call_result.is_err() { - log!("There was an error contacting Hello NEAR"); - return "".to_string(); - } - - // Return the greeting - let greeting: String = call_result.unwrap(); - greeting - } - - // Public - change external greeting - pub fn change_greeting(&mut self, new_greeting: String) -> Promise { - // Create a promise to call HelloNEAR.set_greeting(message:string) - hello_near::ext(self.hello_account.clone()) - .with_static_gas(Gas::from_tgas(5)) - .set_greeting(new_greeting) - .then( - // Create a callback change_greeting_callback - Self::ext(env::current_account_id()) - .with_static_gas(Gas::from_tgas(5)) - .change_greeting_callback(), - ) - } - - #[private] - pub fn change_greeting_callback( - &mut self, - #[callback_result] call_result: Result<(), PromiseError>, - ) -> bool { - // Return whether or not the promise succeeded using the method outlined in external.rs - if call_result.is_err() { - env::log_str("set_greeting failed..."); - return false; - } else { - env::log_str("set_greeting was successful!"); - return true; - } - } } #[cfg(test)] diff --git a/contract-simple-rs/src/low_level.rs b/contract-simple-rs/src/low_level.rs new file mode 100644 index 0000000..3c40027 --- /dev/null +++ b/contract-simple-rs/src/low_level.rs @@ -0,0 +1,73 @@ +use near_sdk::{env, log, near, serde_json::json, Promise, PromiseError}; + +use crate::{Contract, ContractExt, NO_ARGS, NO_DEPOSIT, TEN_TGAS}; + +#[near] +impl Contract { + // Public - query external greeting + pub fn ll_query_greeting(&self) -> Promise { + // Create a promise to call HelloNEAR.get_greeting() + let hello_promise = Promise::new(self.hello_account.clone()).function_call( + "get_greeting".to_owned(), + NO_ARGS, + NO_DEPOSIT, + TEN_TGAS, + ); + + hello_promise.then( + // Create a promise to callback query_greeting_callback + Self::ext(env::current_account_id()) + .with_static_gas(TEN_TGAS) + .ll_query_greeting_callback(), + ) + } + + #[private] // Public - but only callable by env::current_account_id() + pub fn ll_query_greeting_callback( + &self, + #[callback_result] call_result: Result, + ) -> String { + // Check if the promise succeeded by calling the method outlined in external.rs + if call_result.is_err() { + log!("There was an error contacting Hello NEAR"); + return "".to_string(); + } + + // Return the greeting + let greeting: String = call_result.unwrap(); + greeting + } + + // Public - change external greeting + pub fn ll_change_greeting(&mut self, new_greeting: String) -> Promise { + let args = json!({ "greeting": new_greeting }).to_string().into_bytes(); + let hello_promise = Promise::new(self.hello_account.clone()).function_call( + "set_greeting".to_owned(), + args, + NO_DEPOSIT, + TEN_TGAS, + ); + + hello_promise.then( + // Create a promise to callback query_greeting_callback + Self::ext(env::current_account_id()) + .with_static_gas(TEN_TGAS) + .ll_change_greeting_callback(), + ) + } + + #[private] + pub fn ll_change_greeting_callback( + &mut self, + #[callback_result] call_result: Result<(), PromiseError>, + ) -> bool { + // Return whether or not the promise succeeded using the method outlined in external.rs + if call_result.is_err() { + env::log_str("set_greeting failed..."); + false + } else { + env::log_str("set_greeting was successful!"); + true + } + } +} diff --git a/contract-simple-rs/tests/hello-near/Cargo.toml b/contract-simple-rs/tests/hello-near/Cargo.toml new file mode 100644 index 0000000..eaecaac --- /dev/null +++ b/contract-simple-rs/tests/hello-near/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "hello-near" +description = "Hello Near Example" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +near-sdk = "5.6.0" + +[dev-dependencies] +near-sdk = { version = "5.6.0", features = ["unit-testing"] } +near-workspaces = { version = "0.15.0", features = ["unstable"] } +tokio = { version = "1.12.0", features = ["full"] } +serde_json = "1" diff --git a/contract-simple-rs/tests/hello-near/hello-near.wasm b/contract-simple-rs/tests/hello-near/hello-near.wasm deleted file mode 100755 index c568536..0000000 Binary files a/contract-simple-rs/tests/hello-near/hello-near.wasm and /dev/null differ diff --git a/contract-simple-rs/tests/hello-near/src/lib.rs b/contract-simple-rs/tests/hello-near/src/lib.rs new file mode 100644 index 0000000..188be11 --- /dev/null +++ b/contract-simple-rs/tests/hello-near/src/lib.rs @@ -0,0 +1,55 @@ +// Find all our documentation at https://docs.near.org +use near_sdk::{log, near}; + +// Define the contract structure +#[near(contract_state)] +pub struct Contract { + greeting: String, +} + +// Define the default, which automatically initializes the contract +impl Default for Contract { + fn default() -> Self { + Self { + greeting: "Hello".to_string(), + } + } +} + +// Implement the contract structure +#[near] +impl Contract { + // Public method - returns the greeting saved, defaulting to DEFAULT_GREETING + pub fn get_greeting(&self) -> String { + self.greeting.clone() + } + + // Public method - accepts a greeting, such as "howdy", and records it + pub fn set_greeting(&mut self, greeting: String) { + log!("Saving greeting: {}", greeting); + self.greeting = greeting; + } +} + +/* + * The rest of this file holds the inline tests for the code above + * Learn more about Rust tests: https://doc.rust-lang.org/book/ch11-01-writing-tests.html + */ +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn get_default_greeting() { + let contract = Contract::default(); + // this test did not call set_greeting so should return the default "Hello" greeting + assert_eq!(contract.get_greeting(), "Hello"); + } + + #[test] + fn set_then_get_greeting() { + let mut contract = Contract::default(); + contract.set_greeting("howdy".to_string()); + assert_eq!(contract.get_greeting(), "howdy"); + } +} diff --git a/contract-simple-rs/tests/tests.rs b/contract-simple-rs/tests/tests.rs index 75d3d41..b40226c 100644 --- a/contract-simple-rs/tests/tests.rs +++ b/contract-simple-rs/tests/tests.rs @@ -1,16 +1,18 @@ use near_workspaces::{types::NearToken, Account, Contract}; use serde_json::json; - + #[tokio::test] async fn main() -> Result<(), Box> { let worker = near_workspaces::sandbox().await?; - // Deploy hello contract - let hello_contract_wasm = std::fs::read("./tests/hello-near/hello-near.wasm")?; - let hello_contract = worker.dev_deploy(&hello_contract_wasm).await?; + + // Build and deploy hello contract + let hello_contract_wasm = near_workspaces::compile_project("./tests/hello-near").await?; + let hello_contract: Contract = worker.dev_deploy(&hello_contract_wasm).await?; + // Deploy contract for testing let contract_wasm = near_workspaces::compile_project("./").await?; let contract = worker.dev_deploy(&contract_wasm).await?; - + // Create accounts let account = worker.dev_create_account().await?; let alice = account @@ -27,51 +29,78 @@ async fn main() -> Result<(), Box> { .transact() .await? .into_result()?; - + // Begin tests - test_default_greeting(&alice, &contract).await?; - test_change_greeting(&alice, &contract).await?; + test_hl_default_greeting(&alice, &contract).await?; + test_hl_change_greeting(&alice, &contract).await?; + test_ll_change_greeting(&alice, &contract).await?; Ok(()) } -async fn test_default_greeting( +async fn test_hl_default_greeting( user: &Account, contract: &Contract, ) -> Result<(), Box> { let greeting: String = user - .call(contract.id(), "query_greeting") + .call(contract.id(), "hl_query_greeting") .args_json(json!({})) .max_gas() .transact() .await? .json()?; - + assert_eq!(greeting, "Hello".to_string()); Ok(()) } -async fn test_change_greeting( - user: &Account, - contract: &Contract, +async fn test_hl_change_greeting( + user: &Account, + contract: &Contract, ) -> Result<(), Box> { - let result: bool = user - .call(contract.id(), "change_greeting") - .args_json(json!({ "new_greeting": "Howdy" })) - .max_gas() - .transact() - .await? - .json()?; - - assert_eq!(result, true); - - let greeting: String = user - .call(contract.id(), "query_greeting") - .args_json(json!({})) - .max_gas() - .transact() - .await? - .json()?; - - assert_eq!(greeting, "Howdy".to_string()); - Ok(()) -} \ No newline at end of file + let result: bool = user + .call(contract.id(), "hl_change_greeting") + .args_json(json!({ "new_greeting": "Howdy" })) + .max_gas() + .transact() + .await? + .json()?; + + assert!(result); + + let greeting: String = user + .call(contract.id(), "hl_query_greeting") + .args_json(json!({})) + .max_gas() + .transact() + .await? + .json()?; + + assert_eq!(greeting, "Howdy".to_string()); + Ok(()) +} + +async fn test_ll_change_greeting( + user: &Account, + contract: &Contract, +) -> Result<(), Box> { + let result: bool = user + .call(contract.id(), "ll_change_greeting") + .args_json(json!({ "new_greeting": "Hello" })) + .max_gas() + .transact() + .await? + .json()?; + + assert!(result); + + let greeting: String = user + .call(contract.id(), "ll_query_greeting") + .args_json(json!({})) + .max_gas() + .transact() + .await? + .json()?; + + assert_eq!(greeting, "Hello".to_string()); + Ok(()) +} diff --git a/contract-simple-ts/package.json b/contract-simple-ts/package.json index d3eed25..d4354b7 100644 --- a/contract-simple-ts/package.json +++ b/contract-simple-ts/package.json @@ -8,13 +8,13 @@ "test": "$npm_execpath build && ava -- ./build/cross_contract.wasm" }, "dependencies": { - "near-cli": "^4.0.10", - "near-sdk-js": "1.0.0" + "near-cli": "^4.0.13", + "near-sdk-js": "2.0.0" }, "devDependencies": { "@ava/typescript": "^4.1.0", "ava": "^6.1.2", - "near-workspaces": "^3.5.0", + "near-workspaces": "^4.0.0", "ts-morph": "^22.0.0", "ts-node": "^10.9.2", "tsimp": "^2.0.11",