-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test case for contract migration with non-trivial migration…
… data
- Loading branch information
Showing
11 changed files
with
95 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
...ges/axelar-soroban-std/src/contract_traits/testdata/test_format_last_emitted_event.golden
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
packages/axelar-soroban-std/src/interfaces/testdata/contract_non_trivial_migration.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// this is only needed in this crate itself, any crate that imports this one doesn't have to do this manual import resolution | ||
use crate as axelar_soroban_std; | ||
|
||
use crate::interfaces::testdata::contract_trivial_migration::DataKey; | ||
use crate::interfaces::{operatable, ownable, MigratableInterface}; | ||
use axelar_soroban_std_derive::{Ownable, Upgradable}; | ||
use soroban_sdk::{contract, contracterror, contractimpl, contracttype, Address, Env, String}; | ||
|
||
#[derive(Upgradable, Ownable)] | ||
#[migratable(with_type = MigrationData)] | ||
#[contract] | ||
pub struct ContractNonTrivial; | ||
|
||
#[contracttype] | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct MigrationData { | ||
pub data1: String, | ||
pub data2: bool, | ||
pub data3: u32, | ||
} | ||
|
||
#[contractimpl] | ||
impl ContractNonTrivial { | ||
pub fn __constructor(_env: Env, owner: Option<Address>, operator: Option<Address>) { | ||
if let Some(owner) = owner { | ||
ownable::set_owner(&_env, &owner); | ||
} | ||
|
||
if let Some(operator) = operator { | ||
operatable::set_operator(&_env, &operator); | ||
} | ||
} | ||
|
||
pub fn migration_data(env: &Env) -> Option<String> { | ||
env.storage().instance().get(&DataKey::Data) | ||
} | ||
|
||
fn run_migration(env: &Env, migration_data: MigrationData) { | ||
env.storage() | ||
.instance() | ||
.set(&DataKey::Data, &migration_data.data1); | ||
} | ||
} | ||
|
||
#[contracterror] | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] | ||
#[repr(u32)] | ||
pub enum ContractError { | ||
MigrationNotAllowed = 1, | ||
} |
Binary file added
BIN
+3.77 KB
packages/axelar-soroban-std/src/interfaces/testdata/contract_non_trivial_migration.wasm
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod contract; | ||
mod contract_non_trivial_migration; | ||
mod contract_trivial_migration; | ||
|
||
pub use contract::{Contract, ContractClient}; | ||
pub use contract_non_trivial_migration::{ContractNonTrivialClient, MigrationData}; | ||
pub use contract_trivial_migration::{Contract, ContractClient}; |
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
...stdata/trivial_migrate_succeeds_if_owner_is_authenticated_and_called_after_upgrade.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M) | ||
topics: (Symbol(upgraded)) | ||
data: (String(0.1.0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters