Skip to content

Commit

Permalink
e2e: ictest-clock
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Aug 18, 2023
1 parent 421114b commit e3bf4a6
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/interchaintest-E2E.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
- "ictest-unity-gov"
- "ictest-pob"
- "ictest-drip"
- "ictest-clock"
fail-fast: false

steps:
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ ictest-pob: rm-testcache
ictest-drip: rm-testcache
cd interchaintest && go test -race -v -run TestJunoDrip .

ictest-clock: rm-testcache
cd interchaintest && go test -race -v -run TestJunoClock .

rm-testcache:
go clean -testcache

Expand Down
7 changes: 7 additions & 0 deletions interchaintest/helpers/query_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func GetUnityContractWithdrawalReadyTime(t *testing.T, ctx context.Context, chai
return res
}

func GetClockContractValue(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contract string) ClockContractResponse {
var res ClockContractResponse
err := chain.QueryContract(ctx, contract, QueryMsg{GetConfig: &struct{}{}}, &res)
require.NoError(t, err)
return res
}

// From stakingtypes.Validator
type Vals struct {
Validators []struct {
Expand Down
7 changes: 7 additions & 0 deletions interchaintest/helpers/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ type GetCountResponse struct {
type GetCountObj struct {
Count int64 `json:"count"`
}

type ClockContractResponse struct {
Data *ClockContractObj `json:"data"`
}
type ClockContractObj struct {
Val uint32 `json:"val"`
}
60 changes: 50 additions & 10 deletions interchaintest/module_clock_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package interchaintest

import (
"context"
"fmt"
"testing"

clocktypes "github.com/CosmosContracts/juno/v17/x/clock/types"
cosmosproto "github.com/cosmos/gogoproto/proto"
"github.com/strangelove-ventures/interchaintest/v7"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
"github.com/strangelove-ventures/interchaintest/v7/testutil"
"github.com/stretchr/testify/require"

helpers "github.com/CosmosContracts/juno/tests/interchaintest/helpers"
)
Expand All @@ -14,8 +21,6 @@ func TestJunoClock(t *testing.T) {
t.Parallel()

cfg := junoConfig
// set allowed address by default to the contract creator
// cfg.ModifyGenesis = cosmos.ModifyGenesis(append(defaultGenesisKV, []cosmos.GenesisKV{

// Base setup
chains := CreateChainWithCustomConfig(t, 1, 0, cfg)
Expand All @@ -25,21 +30,56 @@ func TestJunoClock(t *testing.T) {
juno := chains[0].(*cosmos.CosmosChain)

// Users
users := interchaintest.GetAndFundTestUsers(t, ctx, "default", int64(10_000_000), juno, juno)
users := interchaintest.GetAndFundTestUsers(t, ctx, "default", int64(10_000_000_000), juno, juno)
user := users[0]

// Upload & init contract payment to another address
_, _ = helpers.SetupContract(t, ctx, juno, user.KeyName(), "contracts/clock_example.wasm", `{}`)
_, contractAddr := helpers.SetupContract(t, ctx, juno, user.KeyName(), "contracts/clock_example.wasm", `{}`)

// wait 1 block
// query the contractAddress config & see if it increased.
// pub struct Config {
// pub val: u32,
// }
// Ensure config is 0
res := helpers.GetClockContractValue(t, ctx, juno, contractAddr)
fmt.Printf("- res: %v\n", res.Data.Val)
require.Equal(t, uint32(0), res.Data.Val)

// TODO: param proposal to add the contract address to the allowed list? or remove it and see if it still increments.
// Submit the proposal to add it to the allowed contracts list
SubmitParamChangeProp(t, ctx, juno, user, []string{contractAddr})

// Wait 1 block
_ = testutil.WaitForBlocks(ctx, 1, juno)

// Validate the contract is now auto incrementing from the end blocker
res = helpers.GetClockContractValue(t, ctx, juno, contractAddr)
fmt.Printf("- res: %v\n", res.Data.Val)
require.GreaterOrEqual(t, res.Data.Val, uint32(1))

t.Cleanup(func() {
_ = ic.Close()
})
}

func SubmitParamChangeProp(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contracts []string) string {
govAcc := "juno10d07y265gmmuvt4z0w9aw880jnsr700jvss730"
updateParams := []cosmosproto.Message{
&clocktypes.MsgUpdateParams{
Authority: govAcc,
Params: clocktypes.NewParams(contracts),
},
}

proposal, err := chain.BuildProposal(updateParams, "Params Add Contract", "params", "ipfs://CID", fmt.Sprintf(`500000000%s`, chain.Config().Denom))
require.NoError(t, err, "error building proposal")

txProp, err := chain.SubmitProposal(ctx, user.KeyName(), proposal)
t.Log("txProp", txProp)
require.NoError(t, err, "error submitting proposal")

height, _ := chain.Height(ctx)

err = chain.VoteOnProposalAllValidators(ctx, txProp.ProposalID, cosmos.ProposalVoteYes)
require.NoError(t, err, "failed to submit votes")

_, err = cosmos.PollForProposalStatus(ctx, chain, height, height+haltHeightDelta, txProp.ProposalID, cosmos.ProposalStatusPassed)
require.NoError(t, err, "proposal status did not change to passed in expected number of blocks")

return txProp.ProposalID
}
2 changes: 2 additions & 0 deletions interchaintest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
testutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
ibclocalhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost"

clocktypes "github.com/CosmosContracts/juno/v17/x/clock/types"
feesharetypes "github.com/CosmosContracts/juno/v17/x/feeshare/types"
tokenfactorytypes "github.com/CosmosContracts/juno/v17/x/tokenfactory/types"
)
Expand Down Expand Up @@ -93,6 +94,7 @@ func junoEncoding() *testutil.TestEncodingConfig {
wasmtypes.RegisterInterfaces(cfg.InterfaceRegistry)
feesharetypes.RegisterInterfaces(cfg.InterfaceRegistry)
tokenfactorytypes.RegisterInterfaces(cfg.InterfaceRegistry)
clocktypes.RegisterInterfaces(cfg.InterfaceRegistry)

return &cfg
}
Expand Down
3 changes: 2 additions & 1 deletion x/clock/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package types
import (
"cosmossdk.io/errors"

"github.com/CosmosContracts/juno/v17/x/drip/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/CosmosContracts/juno/v17/x/drip/types"
)

// Sudo Message called on the contracts
Expand Down

0 comments on commit e3bf4a6

Please sign in to comment.