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

cosmwasm: added shutdown contracts tests #4257

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ jobs:
matrix:
manifest:
- path: cosmwasm/Cargo.toml
args: "--workspace --locked"
args: "--workspace --locked --exclude 'shutdown-*'"
- path: cosmwasm/Cargo.toml
args: "-p 'shutdown-*' --no-default-features --locked"
- path: terra/Cargo.toml
args: "--workspace --locked"
- path: sdk/rust/Cargo.toml
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/wormchain-icts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
outputs: type=docker,dest=${{ env.TAR_PATH }}

- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.IMAGE_NAME }}
path: ${{ env.TAR_PATH }}
Expand All @@ -64,6 +64,7 @@ jobs:
- "ictest-ibc-receiver"
- "ictest-validator-hotswap"
- "ictest-cw-wormhole"
- "ictest-cw-shutdown-contracts"
fail-fast: false

steps:
Expand All @@ -77,7 +78,7 @@ jobs:
uses: actions/checkout@v4

- name: Download Tarball Artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.IMAGE_NAME }}
path: /tmp
Expand Down
11 changes: 11 additions & 0 deletions cosmwasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cosmwasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ panic = 'abort'
incremental = false
overflow-checks = true

[workspace.package]
shutdown-core-bridge-cosmwasm = { path = "contracts/shutdown-wormhole", default-features = false}

[workspace.dependencies.serde_wormhole]
version = "0.1.0"
path = "../sdk/rust/serde_wormhole"
Expand Down
2 changes: 2 additions & 0 deletions cosmwasm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ COPY cosmwasm/artifacts /code/artifacts
COPY sdk/rust /sdk/rust

RUN --mount=type=cache,target=/target,id=cosmwasm_target --mount=type=cache,target=/usr/local/cargo/registry optimize.sh .
# Build only shutdown contracts with no default features
RUN --mount=type=cache,target=/target,id=cosmwasm_target --mount=type=cache,target=/usr/local/cargo/registry optimize.sh ./contracts/shutdown-wormhole

FROM scratch as artifacts
COPY --from=builder /code/artifacts /
3 changes: 2 additions & 1 deletion cosmwasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ tools/node_modules: tools/package-lock.json
.PHONY: test
## Run unit tests
test:
cargo test --workspace --locked
cargo test --workspace --locked --exclude 'shutdown-*'
cargo test -p 'shutdown-*' --no-default-features --locked


.PHONY: clean
Expand Down
13 changes: 13 additions & 0 deletions cosmwasm/contracts/shutdown-wormhole/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
wormhole-cosmwasm = { version = "0.1.0", default-features = false }

[dev-dependencies]
cw-multi-test = "0.14"
serde_wormhole.workspace = true
wormhole-sdk.workspace = true
wormhole-bindings = { version = "0.1", features = ["fake"] }
tiny-keccak = { version = "2.0", features = ["keccak"] }
serde-json-wasm = "0.4"
wormchain-ibc-receiver = { path = "../wormchain-ibc-receiver" }
hex = "0.4.2"
serde = { version = "1.0.137", default-features = false, features = ["derive"] }
k256 = { version = "0.11", default-features = false, features = ["ecdsa"] }
cosmwasm-std = { version = "1.0.0" }
2 changes: 2 additions & 0 deletions cosmwasm/contracts/shutdown-wormhole/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pub use cw_wormhole::contract;
#[cfg(test)]
mod testing;
248 changes: 248 additions & 0 deletions cosmwasm/contracts/shutdown-wormhole/src/testing/integration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
use crate::testing::utils::{IntoGuardianAddress, WormholeApp};
use cosmwasm_std::StdResult;
use cosmwasm_std::Uint256;
use cw_multi_test::Executor;
use cw_wormhole::{
msg::QueryMsg,
msg::{ExecuteMsg, GuardianSetInfoResponse},
state::ParsedVAA,
};
use k256::ecdsa::SigningKey;
use wormhole_bindings::fake::{create_gov_vaa_body, SignVaa};
use wormhole_sdk::{
core::{Action, GovernancePacket},
Address, Amount, Chain, GuardianSetInfo,
};

#[test]
fn post_message_blocked_in_shutdown() {
let WormholeApp {
mut app,
wormhole_contract,
user,
..
} = WormholeApp::new_with_faker_guardians();

// Attempt to post a message - should fail due to shutdown
let post_message_response = app.execute_contract(
user.clone(),
wormhole_contract.clone(),
&ExecuteMsg::PostMessage {
message: b"test".into(),
nonce: 2,
},
&[],
);

assert!(
post_message_response.is_err(),
"Post Message should fail in shutdown mode with \"ContractShutdown\""
);
}

#[test]
fn fee_change_blocked_in_shutdown() -> StdResult<()> {
let WormholeApp {
mut app,
wormhole_contract,
wormhole_keeper,
user,
..
} = WormholeApp::new_with_guardians(vec![SigningKey::from_bytes(&[
93, 217, 189, 224, 168, 81, 157, 93, 238, 38, 143, 8, 182, 94, 69, 77, 232, 199, 238, 206,
15, 135, 221, 58, 43, 74, 0, 129, 54, 198, 62, 226,
])
.unwrap()]);

let vaa_body = create_gov_vaa_body(
2,
GovernancePacket {
chain: Chain::Terra2,
action: Action::SetFee {
amount: Amount(Uint256::from(18u128).to_be_bytes()),
},
},
);

let (_, signed_vaa) = vaa_body.clone().sign_vaa(&wormhole_keeper);

// Attempt to submit fee change VAA - should fail due to shutdown
let vaa_response = app.execute_contract(
user.clone(),
wormhole_contract.clone(),
&ExecuteMsg::SubmitVAA {
vaa: signed_vaa.clone(),
},
&[],
);
println!("vaa resp {:?}", vaa_response);

assert!(
vaa_response.is_err(),
"SetFee VAA submission should fail in shutdown mode with \"ContractShutdown\""
);

Ok(())
}

#[test]
fn transfer_fee_blocked_in_shutdown() -> StdResult<()> {
let WormholeApp {
mut app,
wormhole_contract,
wormhole_keeper,
user,
..
} = WormholeApp::new_with_guardians(vec![SigningKey::from_bytes(&[
93, 217, 189, 224, 168, 81, 157, 93, 238, 38, 143, 8, 182, 94, 69, 77, 232, 199, 238, 206,
15, 135, 221, 58, 43, 74, 0, 129, 54, 198, 62, 226,
])
.unwrap()]);

let vaa_body = create_gov_vaa_body(
2,
GovernancePacket {
chain: Chain::Terra2,
action: Action::TransferFee {
amount: Amount(Uint256::from(100u128).to_be_bytes()),
recipient: Address([1u8; 32]),
},
},
);

let (_, signed_vaa) = vaa_body.clone().sign_vaa(&wormhole_keeper);

// Attempt to submit transfer fee VAA - should fail due to shutdown
let vaa_response = app.execute_contract(
user.clone(),
wormhole_contract.clone(),
&ExecuteMsg::SubmitVAA {
vaa: signed_vaa.clone(),
},
&[],
);

assert!(
vaa_response.is_err(),
"TransferFee VAA submission should fail in shutdown mode with \"ContractShutdown\""
);

Ok(())
}

#[test]
pub fn guardian_set_update_allowed_in_shutdown() -> StdResult<()> {
let WormholeApp {
mut app,
wormhole_contract,
wormhole_keeper,
user,
..
} = WormholeApp::new_with_guardians(vec![SigningKey::from_bytes(&[
93, 217, 189, 224, 168, 81, 157, 93, 238, 38, 143, 8, 182, 94, 69, 77, 232, 199, 238, 206,
15, 135, 221, 58, 43, 74, 0, 129, 54, 198, 62, 226,
])
.unwrap()]);

// Query the current guardian set
let guardian_set_response: GuardianSetInfoResponse = app
.wrap()
.query_wasm_smart(wormhole_contract.clone(), &QueryMsg::GuardianSetInfo {})?;

let new_guardian_keys = vec![
SigningKey::from_bytes(&[
93, 217, 189, 224, 168, 81, 157, 93, 238, 38, 143, 8, 182, 94, 69, 77, 232, 199, 238,
206, 15, 135, 221, 58, 43, 74, 0, 129, 54, 198, 62, 226,
])
.unwrap(),
SigningKey::from_bytes(&[
150, 48, 135, 223, 194, 186, 243, 139, 177, 8, 126, 32, 210, 57, 42, 28, 29, 102, 196,
201, 106, 136, 40, 149, 218, 150, 240, 213, 192, 128, 161, 245,
])
.unwrap(),
];

let update_guardian_set_vaa_body = create_gov_vaa_body(
2,
GovernancePacket {
chain: Chain::Terra2,
action: Action::GuardianSetUpgrade {
new_guardian_set_index: guardian_set_response.guardian_set_index + 1,
new_guardian_set: GuardianSetInfo {
addresses: new_guardian_keys
.iter()
.map(|key| -> wormhole_sdk::GuardianAddress {
key.clone().into_guardian_address()
})
.collect(),
},
},
},
);

let (_, signed_guardian_set_update_vaa) = update_guardian_set_vaa_body
.clone()
.sign_vaa(&wormhole_keeper);

// Submit guardian set update VAA - should succeed despite shutdown
let guardian_set_update_response = app.execute_contract(
user.clone(),
wormhole_contract.clone(),
&ExecuteMsg::SubmitVAA {
vaa: signed_guardian_set_update_vaa.clone(),
},
&[],
);

assert!(
guardian_set_update_response.is_ok(),
"Guardian set update should succeed even in shutdown mode"
);

// Verify the guardian set was actually updated
let new_guardian_set_response: GuardianSetInfoResponse = app
.wrap()
.query_wasm_smart(wormhole_contract.clone(), &QueryMsg::GuardianSetInfo {})?;

assert_eq!(
new_guardian_set_response.guardian_set_index,
guardian_set_response.guardian_set_index + 1,
"Guardian set index should be incremented"
);
assert_eq!(
new_guardian_set_response.addresses.len(),
2,
"New guardian set should have 2 guardians"
);

Ok(())
}

#[test]
pub fn verify_vaa_allowed_in_shutdown() -> StdResult<()> {
let WormholeApp {
app,
wormhole_contract,
wormhole_keeper,
..
} = WormholeApp::new_with_faker_guardians();

let (_, signed_vaa) = create_gov_vaa_body(1, "test").sign_vaa(&wormhole_keeper);

// Query verify VAA - should work despite shutdown
let parsed_vaa: ParsedVAA = app.wrap().query_wasm_smart(
wormhole_contract.clone(),
&QueryMsg::VerifyVAA {
vaa: signed_vaa,
block_time: app.block_info().height,
},
)?;

assert_eq!(parsed_vaa.version, 1, "version should match");
assert_eq!(
parsed_vaa.guardian_set_index, 0,
"guardian set index should match"
);

Ok(())
}
2 changes: 2 additions & 0 deletions cosmwasm/contracts/shutdown-wormhole/src/testing/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod integration;
mod utils;
Loading
Loading