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

migration test #78

Merged
merged 2 commits into from
Aug 23, 2023
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
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
Loading