Skip to content

Commit

Permalink
wip: migration test
Browse files Browse the repository at this point in the history
  • Loading branch information
petersalomonsen committed Dec 24, 2023
1 parent 86f7d45 commit 018ec17
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
46 changes: 46 additions & 0 deletions nearcontract/Cargo.lock

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

4 changes: 4 additions & 0 deletions nearcontract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ ed25519-dalek = "1.0.1"

[dev-dependencies]
near-workspaces = { version = "0.9.0", features = ["unstable"] }
tokio = { version = "1.10.0", features = ["full"] }
anyhow = "1.0"
near-units = "0.2.0"
serde_json = { version = "1.0", features = ["arbitrary_precision"] }

[profile.release]
codegen-units = 1
Expand Down
14 changes: 14 additions & 0 deletions nearcontract/tests/migration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mod test_env;

use {crate::test_env::*, serde_json::json};

#[tokio::test]
async fn test_deploy_contract_self_upgrade() -> anyhow::Result<()> {
let contract = init_contracts().await?;
let wasm = near_workspaces::compile_project("./").await?;

let mut contract_upgrade_result =
contract.call("unsafe_self_upgrade").args(wasm).max_gas().transact().await?;

Ok(())
}
22 changes: 22 additions & 0 deletions nearcontract/tests/test_env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use near_units::parse_near;
use near_workspaces::{AccountId, types::NearToken};
use serde_json::json;

const WASMGIT_CONTRACT: &str = "wasmgit.near";

pub async fn init_contracts() -> anyhow::Result<near_workspaces::Contract> {
let worker = near_workspaces::sandbox().await?;
let mainnet = near_workspaces::mainnet_archival().await?;

let contract_id: AccountId = WASMGIT_CONTRACT.parse()?;
let contract = worker
.import_contract(&contract_id, &mainnet)
.initial_balance(NearToken::from_near(parse_near!("1000 N")))
.transact()
.await?;
let outcome = contract.call("new").args_json(json!({})).transact().await?;
assert!(outcome.is_success());
assert!(format!("{:?}", outcome).contains("Migrated to version:"));

Ok(contract)
}

0 comments on commit 018ec17

Please sign in to comment.