11mod setup;
2+ use near_sdk:: serde_json:: json;
3+ use satoshi_bridge:: Account ;
24use 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]
75113async fn test_set_icon ( ) {
76114 let worker = near_workspaces:: sandbox ( ) . await . unwrap ( ) ;
0 commit comments