Skip to content

Commit

Permalink
e2e: updated ownership assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Nov 25, 2023
1 parent b6a3681 commit 9a7f8f2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 7 deletions.
17 changes: 13 additions & 4 deletions e2e/interchaintest/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ func (s *ContractTestSuite) SetupContractTestSuite(ctx context.Context, encoding
contractState, err := s.Contract.QueryContractState(ctx)
s.Require().NoError(err)

ownershipResponse, err := s.Contract.QueryOwnership(ctx)
s.Require().NoError(err)

s.IcaAddress = contractState.IcaInfo.IcaAddress
s.Contract.SetIcaAddress(s.IcaAddress)

s.Require().Equal(s.UserA.FormattedAddress(), ownershipResponse.Owner)
s.Require().Nil(ownershipResponse.PendingOwner)
s.Require().Nil(ownershipResponse.PendingExpiry)
}

func TestWithContractTestSuite(t *testing.T) {
Expand All @@ -73,7 +80,6 @@ func (s *ContractTestSuite) TestIcaContractChannelHandshake() {
// sets up the contract and does the channel handshake for the contract test suite.
s.SetupContractTestSuite(ctx, icatypes.EncodingProto3JSON)
wasmd, simd := s.ChainA, s.ChainB
wasmdUser := s.UserA

s.Run("TestChannelHandshakeSuccess", func() {
// Test if the handshake was successful
Expand Down Expand Up @@ -122,8 +128,8 @@ func (s *ContractTestSuite) TestIcaContractChannelHandshake() {
contractState, err := s.Contract.QueryContractState(ctx)
s.Require().NoError(err)

s.Require().Equal(wasmdUser.FormattedAddress(), contractState.Admin)
s.Require().Equal(wasmdChannel.ChannelID, contractState.IcaInfo.ChannelID)
s.Require().Equal(false, contractState.AllowChannelOpenInit)
})
}

Expand Down Expand Up @@ -156,7 +162,10 @@ func (s *ContractTestSuite) TestIcaRelayerInstantiatedChannelHandshake() {

contractState, err := s.Contract.QueryContractState(ctx)
s.Require().NoError(err)
s.Require().Equal(true, contractState.AllowChannelOpenInit)

s.IcaAddress = contractState.IcaInfo.IcaAddress
s.Contract.SetIcaAddress(s.IcaAddress)

s.Run("TestChannelHandshakeSuccess", func() {
// Test if the handshake was successful
Expand Down Expand Up @@ -205,8 +214,8 @@ func (s *ContractTestSuite) TestIcaRelayerInstantiatedChannelHandshake() {
contractState, err := s.Contract.QueryContractState(ctx)
s.Require().NoError(err)

s.Require().Equal(wasmdUser.FormattedAddress(), contractState.Admin)
s.Require().Equal(wasmdChannel.ChannelID, contractState.IcaInfo.ChannelID)
s.Require().Equal(false, contractState.AllowChannelOpenInit)
})
}

Expand Down Expand Up @@ -294,8 +303,8 @@ func (s *ContractTestSuite) TestRecoveredIcaContractInstantiatedChannelHandshake
contractState, err := s.Contract.QueryContractState(ctx)
s.Require().NoError(err)

s.Require().Equal(wasmdUser.FormattedAddress(), contractState.Admin)
s.Require().Equal(wasmdChannel.ChannelID, contractState.IcaInfo.ChannelID)
s.Require().Equal(false, contractState.AllowChannelOpenInit)
})
}

Expand Down
9 changes: 7 additions & 2 deletions e2e/interchaintest/owner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,14 @@ func (s *OwnerTestSuite) TestOwnerCreateIcaContract() {
// Check contract state
contractState, err := icaContract.QueryContractState(ctx)
s.Require().NoError(err)

s.Require().Equal(s.OwnerContract.Address, contractState.Admin)
s.Require().Equal(wasmdChannel.ChannelID, contractState.IcaInfo.ChannelID)
s.Require().Equal(false, contractState.AllowChannelOpenInit)

ownerResponse, err := icaContract.QueryOwnership(ctx)
s.Require().NoError(err)
s.Require().Equal(s.OwnerContract.Address, ownerResponse.Owner)
s.Require().Nil(ownerResponse.PendingOwner)
s.Require().Nil(ownerResponse.PendingExpiry)
})
}

Expand Down
16 changes: 16 additions & 0 deletions e2e/interchaintest/types/ica_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,19 @@ func (c *IcaContract) QueryCallbackCounter(ctx context.Context) (*IcaContractCal

return &callbackCounter, nil
}

// QueryOwnership queries the owner of the contract
func (c *IcaContract) QueryOwnership(ctx context.Context) (*OwnershipQueryResponse, error) {
queryResp := QueryResponse[OwnershipQueryResponse]{}
err := c.chain.QueryContract(ctx, c.Address, newOwnershipQueryMsg(), &queryResp)
if err != nil {
return nil, err
}

ownershipResp, err := queryResp.GetResp()
if err != nil {
return nil, err
}

return &ownershipResp, nil
}
23 changes: 23 additions & 0 deletions e2e/interchaintest/types/ica_query.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package types

import "encoding/json"

// newGetChannelQueryMsg creates a new GetChannelQueryMsg.
// This function returns a map[string]interface{} instead of []byte
// because interchaintest uses json.Marshal to convert the map to a string
Expand All @@ -26,3 +28,24 @@ func newGetCallbackCounterQueryMsg() map[string]interface{} {
"get_callback_counter": struct{}{},
}
}

// newOwnershipQueryMsg creates a new OwnershipQueryMsg.
// This function returns a map[string]interface{} instead of []byte
// because interchaintest uses json.Marshal to convert the map to a string
func newOwnershipQueryMsg() map[string]interface{} {
return map[string]interface{}{
"ownership": struct{}{},
}
}

// OwnershipQueryResponse is the response type for the OwnershipQueryMsg
type OwnershipQueryResponse struct {
// The current owner of the contract.
// This contract must have an owner.
Owner string `json:"owner"`
// The pending owner of the contract if one exists.
PendingOwner *string `json:"pending_owner"`
// The height at which the pending owner offer expires.
// Not sure how to represent this, so we'll just use a raw message
PendingExpiry *json.RawMessage `json:"pending_expiry"`
}
1 change: 0 additions & 1 deletion e2e/interchaintest/types/ica_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

// IcaContractState is used to represent its state in Contract's storage
type IcaContractState struct {
Admin string `json:"admin"`
IcaInfo IcaContractIcaInfo `json:"ica_info"`
AllowChannelOpenInit bool `json:"allow_channel_open_init"`
}
Expand Down

0 comments on commit 9a7f8f2

Please sign in to comment.