Skip to content

Commit 32ca22e

Browse files
committed
add migration test
1 parent c96843b commit 32ca22e

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

contracts/satoshi-bridge/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "satoshi-bridge"
3-
version = "0.7.5"
3+
version = "0.8.0"
44
edition.workspace = true
55
publish.workspace = true
66
repository.workspace = true
-1.06 MB
Binary file not shown.
1.2 MB
Binary file not shown.

contracts/satoshi-bridge/tests/test_upgrade.rs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
mod setup;
2+
use near_sdk::serde_json::json;
3+
use satoshi_bridge::Account;
24
use setup::*;
35

46
#[tokio::test]
@@ -16,11 +18,11 @@ async fn test_btc_bridge_upgrade() {
1618
}
1719

1820
#[tokio::test]
19-
async fn test_btc_bridge_upgrade_from_v0_5_1() {
21+
async fn test_btc_bridge_upgrade_from_v0_7_5() {
2022
let worker = near_workspaces::sandbox().await.unwrap();
2123
let upgrade_context = UpgradeContext::new(
2224
&worker,
23-
"tests/data/btc_bridge_v0-5-1.wasm",
25+
"tests/data/btc_bridge_v0-7-5.wasm",
2426
"tests/data/nbtc_v0-5-1.wasm",
2527
)
2628
.await;
@@ -62,7 +64,7 @@ async fn test_nbtc_upgrade_from_v0_5_1() {
6264
let worker = near_workspaces::sandbox().await.unwrap();
6365
let upgrade_context = UpgradeContext::new(
6466
&worker,
65-
"tests/data/btc_bridge_v0-5-1.wasm",
67+
"tests/data/btc_bridge_v0-7-5.wasm",
6668
"tests/data/nbtc_v0-5-1.wasm",
6769
)
6870
.await;
@@ -71,6 +73,42 @@ async fn test_nbtc_upgrade_from_v0_5_1() {
7173
check!(view upgrade_context.get_nbtc_version());
7274
}
7375

76+
/// After upgrading from v0.7.5 (btc_pending_sign_id: Option<String>)
77+
/// to the current version (btc_pending_sign_ids: HashSet<String>),
78+
/// reading an account created by the old contract must still work.
79+
#[tokio::test]
80+
async fn test_btc_bridge_upgrade_from_v0_7_5_account_migration() {
81+
let worker = near_workspaces::sandbox().await.unwrap();
82+
let upgrade_context = UpgradeContext::new(
83+
&worker,
84+
"tests/data/btc_bridge_v0-7-5.wasm",
85+
"../../res/nbtc.wasm",
86+
)
87+
.await;
88+
89+
// The deployer account (root) was created during contract init on the old version.
90+
// Upgrade to the new version.
91+
check!(upgrade_context.upgrade_satoshi_bridge("../../res/bitcoin_bridge.wasm"));
92+
93+
// get_account must successfully deserialize the old account format.
94+
let account: Option<Account> = upgrade_context
95+
.previous_satoshi_bridge_contract
96+
.call("get_account")
97+
.args_json(json!({"account_id": upgrade_context.root.id()}))
98+
.view()
99+
.await
100+
.unwrap()
101+
.json()
102+
.unwrap();
103+
104+
let account = account.expect("Account must exist after migration");
105+
assert_eq!(
106+
account.account_id.as_str(),
107+
upgrade_context.root.id().as_str()
108+
);
109+
assert!(account.btc_pending_sign_ids.is_empty());
110+
}
111+
74112
#[tokio::test]
75113
async fn test_set_icon() {
76114
let worker = near_workspaces::sandbox().await.unwrap();

0 commit comments

Comments
 (0)