Skip to content

Commit

Permalink
testing: ensure only outpost owner can re-open channel
Browse files Browse the repository at this point in the history
  • Loading branch information
BiPhan4 committed Oct 22, 2024
1 parent 5f75061 commit bee2e93
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
2 changes: 2 additions & 0 deletions e2e/interchaintest/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ go test -v . -run TestWithFactoryTestSuite -testify.m TestMasterMigration -timeo
go test -v . -run TestWithContractTestSuite -testify.m TestIcaContractExecutionTestWithFiletree -timeout 12h
go test -v . -run TestWithContractTestSuite -testify.m TestReOpenOrderedChannel -timeout 12h
go test -v . -run TestWithContractTestSuite -testify.m TestIcaContractExecutionTestWithOwnership -timeout 12h
go test -v . -run TestWithContractTestSuite -testify.m TestIcaContractExecutionTestWithBuyStorage -timeout 12h
Expand Down
23 changes: 6 additions & 17 deletions e2e/interchaintest/logs/test.log
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
INFO: 2024/10/21 15:31:56 Factory contract Info is: address:"wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" contract_info:<code_id:2 creator:"wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag" admin:"wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag" label:"wasm-contract" created:<block_height:53 > ibc_port_id:"wasm.wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" >

INFO: 2024/10/21 15:31:56 Admin of factory is: wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag

INFO: 2024/10/21 15:32:00 outpostContractInfo is: address:"wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay" contract_info:<code_id:1 creator:"wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" admin:"wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" label:"storage_outpost-owned by: wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag" created:<block_height:55 > ibc_port_id:"wasm.wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay" >

INFO: 2024/10/21 15:32:00 Admin of user A's outpost is: wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8

INFO: 2024/10/21 15:32:00 outpostContractState is: data:"{\"admin\":\"wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8\",\"allow_channel_open_init\":true}"

INFO: 2024/10/21 15:32:00 Owner of user A's outpost is: wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag

INFO: 2024/10/21 15:32:00 Mapped outpost address is: wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay

INFO: 2024/10/21 15:32:39 factory map is: data:"[[\"wasm125gw73kajruy5e9xcnpjx60nh6md4gjfvr6ees\",\"wasm1yyca08xqdgvjz0psg56z67ejh9xms6l436u8y58m82npdqqhmmtqas0cl7\"],[\"wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag\",\"wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay\"]]"
INFO: 2024/10/21 15:32:39 Mapping 0: [wasm125gw73kajruy5e9xcnpjx60nh6md4gjfvr6ees wasm1yyca08xqdgvjz0psg56z67ejh9xms6l436u8y58m82npdqqhmmtqas0cl7]
INFO: 2024/10/21 15:32:39 Mapping 1: [wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay]
INFO: 2024/10/22 13:59:08 The sender of instantiate is wasmd-localwasm-1-abm
INFO: 2024/10/22 13:59:19 [0x1400135e000]
INFO: 2024/10/22 14:00:33 <nil>
INFO: 2024/10/22 14:01:06 [{STATE_CLOSED ORDER_ORDERED {wasm.wasm14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s0phg4d channel-0} [connection-0] {"version":"ics27-1","controller_connection_id":"connection-0","host_connection_id":"connection-0","address":"jkl1zh4wgjy33shq4p0hrga7ayn5nzv9pmtcca9h3p4eplnnn7h7xtxqhmfyrd","encoding":"proto3","tx_type":"sdk_multi_msg"} icahost channel-0} {STATE_OPEN ORDER_ORDERED {wasm.wasm14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s0phg4d channel-1} [connection-0] {"version":"ics27-1","controller_connection_id":"connection-0","host_connection_id":"connection-0","address":"jkl1zh4wgjy33shq4p0hrga7ayn5nzv9pmtcca9h3p4eplnnn7h7xtxqhmfyrd","encoding":"proto3","tx_type":"sdk_multi_msg"} icahost channel-1}]
INFO: 2024/10/22 14:01:06 <nil>
INFO: 2024/10/22 14:01:07 channel-1
17 changes: 15 additions & 2 deletions e2e/interchaintest/re_open_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,29 @@ func (s *ContractTestSuite) TestReOpenOrderedChannel() {
})

s.Run("TestReOpenOrderedChannelAndPostKey", func() {

// Ensure that only the owner can re-open the channel

badCreateChannelMsg := testtypes.ExecuteMsg{
CreateChannel: &testtypes.ExecuteMsg_CreateChannel{
ChannelOpenInitOptions: nil, // consequence of not putting open init options?...
},
}

executeErr := s.Contract.Execute(ctx, s.UserA2.KeyName(), badCreateChannelMsg, "--gas", "500000")

expectedCreationErrorMsg := fmt.Sprintf("error in transaction (code: 5): failed to execute message; message index: 0: Caller is not the contract's current owner: execute wasm contract failed")
s.Require().EqualError(executeErr, expectedCreationErrorMsg)

// Reopen the channel:

createChannelMsg := testtypes.ExecuteMsg{
CreateChannel: &testtypes.ExecuteMsg_CreateChannel{
ChannelOpenInitOptions: nil, // consequence of not putting open init options?...
},
}
// contractAddr, err := s.ChainA.InstantiateContract(ctx, s.UserA.KeyName(), codeId, instantiateMsg, false, "--gas", "500000", "--admin", s.UserA.KeyName())

executeErr := s.Contract.Execute(ctx, wasmdUser.KeyName(), createChannelMsg, "--gas", "500000")
executeErr = s.Contract.Execute(ctx, wasmdUser.KeyName(), createChannelMsg, "--gas", "500000")
s.Require().NoError(executeErr)

// Wait for the channel to get set up
Expand Down
5 changes: 0 additions & 5 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ mod execute {
) -> Result<Response, ContractError> {
cw_ownable::assert_owner(deps.storage, &info.sender)?;

// TODO: make this more readable and less confusing?
// TODO: get rid of 'state::' usage
let options = if let Some(new_options) = options {
state::CHANNEL_OPEN_INIT_OPTIONS.save(deps.storage, &new_options)?;
new_options
Expand All @@ -190,9 +188,6 @@ mod execute {
.ok_or(ContractError::NoChannelInitOptions)?
};

// WARNING
// TODO: ponder - I think that 'assert_owner' ensures that only the only can call create_channel and update
// 'ALLOW_CHANNEL_OPEN INIT'. It's also updated during instantiation and the owner is set there
state::ALLOW_CHANNEL_OPEN_INIT.save(deps.storage, &true)?;

let ica_channel_open_init_msg = new_ica_channel_open_init_cosmos_msg(
Expand Down

0 comments on commit bee2e93

Please sign in to comment.