Skip to content

Commit

Permalink
feat(e2e): added wasm proof test
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Jun 14, 2024
1 parent d363051 commit 1a2f383
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- TestWithICS07TendermintTestSuite/TestInstantiate
- TestWithICS07TendermintTestSuite/TestUpdateClient
- TestWithICS07TendermintTestSuite/TestVerifyMembership
- TestWithIBCLiteTestSuite/TestWasmProofs
name: ${{ matrix.test }}
runs-on: ubuntu-latest
steps:
Expand Down
53 changes: 49 additions & 4 deletions e2e/interchaintestv8/ibclite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ func (s *IBCLiteTestSuite) SetupSuite(ctx context.Context) {
_, err := s.BroadcastMessages(ctx, simd, simdRelayerUser, 200_000, &clienttypes.MsgProvideCounterparty{
ClientId: ibctesting.FirstClientID,
CounterpartyId: "08-wasm-0",
MerklePathPrefix: &commitmenttypes.MerklePath{
MerklePathPrefix: &commitmenttypes.MerklePrefix{
// TODO: use wasm path!
KeyPath: []string{ibcexported.StoreKey},
KeyPrefix: []byte(ibcexported.StoreKey),
},
Signer: simdRelayerUser.FormattedAddress(),
})
Expand All @@ -221,11 +221,49 @@ func TestWithIBCLiteTestSuite(t *testing.T) {
suite.Run(t, new(IBCLiteTestSuite))
}

func (s *IBCLiteTestSuite) TestIBCLite() {
// TestIBCLiteSetup tests the setup of the IBC Lite test suite
// TODO: remove this once there are actual tests
func (s *IBCLiteTestSuite) TestIBCLiteSetup() {
ctx := context.Background()
s.SetupSuite(ctx)
}

// This is a test to verify that go clients can prove the state of cosmwasm contracts
// WIP
func (s *IBCLiteTestSuite) TestWasmProofs() {
ctx := context.Background()
s.SetupSuite(ctx)

wasmd, _ := s.ChainA, s.ChainB

s.Require().NoError(s.Relayer.UpdateClients(ctx, s.ExecRep, s.PathName))

// During the setup, we have already committed some state into some contracts.
// Our goal is to prove the ICS02_CLIENT_ADDRESS state in ics26Router contract
var (
proofHeight int64
proof []byte
value []byte
// merklePath commitmenttypes.MerklePath
)
s.Require().True(s.Run("Generate wasm proof", func() {
contractAddr, err := s.ics26Router.AccAddress()
s.Require().NoError(err)

prefixStoreKey := wasmtypes.GetContractStorePrefix(contractAddr)
ics02AddrKey := "ics02_client_address"
key := cloneAppend(prefixStoreKey, []byte(ics02AddrKey))

value, proof, proofHeight, err = s.QueryProofs(ctx, wasmd, wasmtypes.StoreKey, key, int64(s.trustedHeight.RevisionHeight))
s.Require().NoError(err)
s.Require().NotEmpty(proof)
s.Require().NotEmpty(value)
s.Require().Equal(int64(s.trustedHeight.RevisionHeight), proofHeight)
s.Require().Equal(value, []byte(`"`+s.ics02Client.Address+`"`))
}))

// wasmd, _ := s.ChainA, s.ChainB
// TODO: Can't finish this test because ibc-go does not have a way to verify proofs in wasm path:
// https://github.com/cosmos/ibc-go/issues/6496
}

func (s *IBCLiteTestSuite) UpdateClientContract(ctx context.Context, tmContract *ics07tendermint.Contract, counterpartyChain *cosmos.CosmosChain) {
Expand All @@ -252,3 +290,10 @@ func (s *IBCLiteTestSuite) UpdateClientContract(ctx context.Context, tmContract
// NOTE: We assume that revision number does not change
s.trustedHeight.RevisionHeight = uint64(signedHeader.Header.Height)
}

func cloneAppend(bz []byte, tail []byte) (res []byte) {
res = make([]byte, len(bz)+len(tail))
copy(res, bz)
copy(res[len(bz):], tail)
return
}
16 changes: 16 additions & 0 deletions e2e/interchaintestv8/types/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ func (c *Contract[I, E, Q, QC]) Query(ctx context.Context, queryMsg Q, resp any)
return nil
}

// AccAddress returns the sdk.AccAddress for the contract
func (c *Contract[I, E, Q, QC]) AccAddress() (sdk.AccAddress, error) {
sdk.GetConfig().SetBech32PrefixForAccount(c.Chain.Config().Bech32Prefix, c.Chain.Config().Bech32Prefix+sdk.PrefixPublic)
sdk.GetConfig().SetBech32PrefixForValidator(
c.Chain.Config().Bech32Prefix+sdk.PrefixValidator+sdk.PrefixOperator,
c.Chain.Config().Bech32Prefix+sdk.PrefixValidator+sdk.PrefixOperator+sdk.PrefixPublic,
)

contractAddr, err := sdk.AccAddressFromBech32(c.Address)
if err != nil {
return nil, err
}

return contractAddr, nil
}

// this line is used by go-codegen # contract/dir

// toString converts the message to a string using json
Expand Down

0 comments on commit 1a2f383

Please sign in to comment.