-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from near-examples/high-low-level-examples
Adding low-level way to make XCC
- Loading branch information
Showing
22 changed files
with
431 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
contract-advanced-rs/tests/contracts/hello-near/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
55 changes: 55 additions & 0 deletions
55
contract-advanced-rs/tests/contracts/hello-near/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
contract-simple-rs/src/external.rs → contract-simple-rs/src/external_contract.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.