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

Add CI for main branch #11

Merged
merged 2 commits into from
Feb 6, 2024
Merged
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
17 changes: 17 additions & 0 deletions .github/workflows/main.yml
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
14 changes: 14 additions & 0 deletions sandbox-rs/Cargo.toml
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"
68 changes: 68 additions & 0 deletions sandbox-rs/src/tests.rs
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(())
}
*/
Loading