Skip to content

Commit

Permalink
migration test (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Zaremba <[email protected]>
  • Loading branch information
sczembor and robert-zaremba authored Aug 23, 2023
1 parent f57d49f commit 439d571
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/registry/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Contract {
let old_state: OldState = env::state_read().expect("failed");
// new field in the smart contract :
// + flagged: LookupMap<AccountId, AccountFlag>
// + admins_flagged: LazyOption<Vec<AccountId>>
// + authorized_flaggers: LazyOption<Vec<AccountId>>

Self {
authority: old_state.authority.clone(),
Expand Down
38 changes: 35 additions & 3 deletions contracts/registry/tests/workspaces.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use anyhow::Ok;
use near_sdk::serde_json::json;
use near_units::parse_near;
use sbt::{TokenMetadata, ClassSet};
use registry::storage::AccountFlag;
use sbt::{ClassSet, TokenMetadata};
use workspaces::{network::Sandbox, Account, AccountId, Contract, Worker};

const MAINNET_REGISTRY_ID: &str = "registry.i-am-human.near";
Expand Down Expand Up @@ -227,7 +228,7 @@ async fn migration_mainnet() -> anyhow::Result<()> {
// call the migrate method
let res = new_registry_contract
.call("migrate")
.args_json(json!({"authorized_flaggers": ["alice.near"]}))
.args_json(json!({"authorized_flaggers": [alice.id()]}))
.max_gas()
.transact()
.await?;
Expand All @@ -243,12 +244,43 @@ async fn migration_mainnet() -> anyhow::Result<()> {
)
.await?;

let res = new_registry_contract
.call("account_flagged")
.args_json(json!({"account": "bob.near"}))
.max_gas()
.transact()
.await?;
assert!(res.is_success());
let res: Option<AccountFlag> = res.json()?;
assert!(res.is_none());

let res = alice
.call(new_registry_contract.id(), "admin_flag_accounts")
.args_json(
json!({"flag": AccountFlag::Blacklisted,"accounts": vec!["bob.near"], "memo": "test"}),
)
.max_gas()
.transact()
.await?;
assert!(res.is_success());

let res = new_registry_contract
.call("account_flagged")
.args_json(json!({"account": "bob.near"}))
.max_gas()
.transact()
.await?;
assert!(res.is_success());
let res: Option<AccountFlag> = res.json()?;
assert_eq!(res.unwrap(), AccountFlag::Blacklisted);

Ok(())
}

#[ignore = "this test is not valid after the migration"]
// handler error: [State of contract registry.i-am-human.near is too large to be viewed]
// For current block 99,142,922
// The current running registry contract is too large to be viewed.
// This test cannot be perfomed on real data anymore
#[tokio::test]
async fn migration_mainnet_real_data() -> anyhow::Result<()> {
// import the registry contract from mainnet with data
Expand Down

0 comments on commit 439d571

Please sign in to comment.