-
Notifications
You must be signed in to change notification settings - Fork 0
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 #11 from archetype-org/gh-actions
Add CI for main branch
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Main CI | ||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
jobs: | ||
unit-testing: | ||
name: Unit testing | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- uses: Swatinem/rust-cache@v2 | ||
- run: rustup target add wasm32-unknown-unknown | ||
- name: Build and test contract | ||
run: ./build.sh | cargo test |
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,14 @@ | ||
[package] | ||
name = "sandbox" | ||
version = "1.0.0" | ||
publish = false | ||
edition = "2021" | ||
|
||
[dev-dependencies] | ||
tokio = { version = "1.18.1", features = ["full"] } | ||
near-workspaces = "0.9.0" | ||
serde_json = { version = "1.0", features = ["arbitrary_precision"] } | ||
|
||
[[example]] | ||
name = "sandbox" | ||
path = "src/tests.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,68 @@ | ||
use near_workspaces::{types::NearToken, Account, Contract}; | ||
use serde_json::json; | ||
use std::{env, fs}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let wasm_arg: &str = &(env::args().nth(1).unwrap()); | ||
let wasm_filepath = fs::canonicalize(env::current_dir()?.join(wasm_arg))?; | ||
|
||
let worker = near_workspaces::sandbox().await?; | ||
let wasm = std::fs::read(wasm_filepath)?; | ||
let contract = worker.dev_deploy(&wasm).await?; | ||
|
||
// create accounts | ||
let account = worker.dev_create_account().await?; | ||
let alice = account | ||
.create_subaccount("alice") | ||
.initial_balance(NearToken::from_near(30)) | ||
.transact() | ||
.await? | ||
.into_result()?; | ||
|
||
// begin tests | ||
// test_default_message(&alice, &contract).await?; | ||
// test_changes_message(&alice, &contract).await?; | ||
Ok(()) | ||
} | ||
|
||
|
||
/* | ||
async fn test_default_message( | ||
user: &Account, | ||
contract: &Contract, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
let greeting: String = user | ||
.call(contract.id(), "get_greeting") | ||
.args_json(json!({})) | ||
.transact() | ||
.await? | ||
.json()?; | ||
assert_eq!(greeting, "Hello".to_string()); | ||
println!(" Passed ✅ gets default greeting"); | ||
Ok(()) | ||
} | ||
async fn test_changes_message( | ||
user: &Account, | ||
contract: &Contract, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
user.call(contract.id(), "set_greeting") | ||
.args_json(json!({"greeting": "Howdy"})) | ||
.transact() | ||
.await? | ||
.into_result()?; | ||
let greeting: String = user | ||
.call(contract.id(), "get_greeting") | ||
.args_json(json!({})) | ||
.transact() | ||
.await? | ||
.json()?; | ||
assert_eq!(greeting, "Howdy".to_string()); | ||
println!(" Passed ✅ changes greeting"); | ||
Ok(()) | ||
} | ||
*/ |