Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Jun 12, 2024
1 parent 22717cd commit eb9dfe6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 148 deletions.
18 changes: 11 additions & 7 deletions tests/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/babylonchain/babylon-sdk/demo/app"
appparams "github.com/babylonchain/babylon-sdk/demo/app/params"
"github.com/babylonchain/babylon-sdk/tests/e2e/types"
bbntypes "github.com/babylonchain/babylon-sdk/x/babylon/types"
zctypes "github.com/babylonchain/babylon/x/zoneconcierge/types"
sdk "github.com/cosmos/cosmos-sdk/types"
ibctesting2 "github.com/cosmos/ibc-go/v8/testing"
Expand Down Expand Up @@ -94,13 +95,16 @@ func (s *BabylonSDKTestSuite) Test1ContractDeployment() {
s.NoError(err)
s.Equal(adminResp["admin"], s.ConsumerCli.GetSender().String())

// update the contract address in parameters (typically this has to be done via gov props)
ctx := s.ConsumerChain.GetContext()
params := s.ConsumerApp.BabylonKeeper.GetParams(ctx)
params.BabylonContractAddress = s.ConsumerContract.Babylon.String()
params.BtcStakingContractAddress = s.ConsumerContract.BTCStaking.String()
err = s.ConsumerApp.BabylonKeeper.SetParams(ctx, params)
s.NoError(err)
// update the contract address in parameters
msgUpdateParams := &bbntypes.MsgUpdateParams{
Authority: s.ConsumerApp.BabylonKeeper.GetAuthority(),
Params: bbntypes.Params{
MaxGasBeginBlocker: 500_000,
BabylonContractAddress: s.ConsumerContract.Babylon.String(),
BtcStakingContractAddress: s.ConsumerContract.BTCStaking.String(),
},
}
s.ConsumerCli.MustExecGovProposal(msgUpdateParams)
}

// TestExample is an example test case
Expand Down
56 changes: 53 additions & 3 deletions tests/e2e/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (

"github.com/CosmWasm/wasmd/x/wasm/ibctesting"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/babylonchain/babylon-sdk/demo/app"
bbntypes "github.com/babylonchain/babylon-sdk/x/babylon/types"
abci "github.com/cometbft/cometbft/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/babylonchain/babylon-sdk/demo/app"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/stretchr/testify/require"
)

// Query is a query type used in tests only
Expand Down Expand Up @@ -156,3 +157,52 @@ func (p *TestConsumerClient) Exec(contract sdk.AccAddress, payload []byte, funds
func (p *TestConsumerClient) Query(contractAddr sdk.AccAddress, query Query) (QueryResponse, error) {
return Querier(p.t, p.Chain)(contractAddr.String(), query)
}

// MustExecGovProposal submit and vote yes on proposal
func (p *TestConsumerClient) MustExecGovProposal(msg *bbntypes.MsgUpdateParams) {
proposalID := submitGovProposal(p.t, p.Chain, msg)
voteAndPassGovProposal(p.t, p.Chain, proposalID)
}

func submitGovProposal(t *testing.T, chain *ibctesting.TestChain, msgs ...sdk.Msg) uint64 {
// get gov module parameters
chainApp := chain.App.(*app.ConsumerApp)
govParams, err := chainApp.GovKeeper.Params.Get(chain.GetContext())
require.NoError(t, err)

// construct proposal
govMsg, err := govv1.NewMsgSubmitProposal(msgs, govParams.MinDeposit, chain.SenderAccount.GetAddress().String(), "", "my title", "my summary", false)
require.NoError(t, err)

// submit proposal
_, err = chain.SendMsgs(govMsg)
require.NoError(t, err)

// get next proposal ID
proposalID, err := chainApp.GovKeeper.ProposalID.Peek(chain.GetContext())
require.NoError(t, err)

return proposalID - 1
}

func voteAndPassGovProposal(t *testing.T, chain *ibctesting.TestChain, proposalID uint64) {
// get gov module parameters
chainApp := chain.App.(*app.ConsumerApp)
govParams, err := chainApp.GovKeeper.Params.Get(chain.GetContext())
require.NoError(t, err)

// construct and submit vote
vote := govv1.NewMsgVote(chain.SenderAccount.GetAddress(), proposalID, govv1.OptionYes, "testing")
_, err = chain.SendMsgs(vote)
require.NoError(t, err)

// pass voting period
coord := chain.Coordinator
coord.IncrementTimeBy(*govParams.VotingPeriod)
coord.CommitBlock(chain)

// ensure proposal is passed
proposal, err := chainApp.GovKeeper.Proposals.Get(chain.GetContext(), proposalID)
require.NoError(t, err)
require.Equal(t, proposal.Status, govv1.ProposalStatus_PROPOSAL_STATUS_PASSED)
}
138 changes: 0 additions & 138 deletions x/babylon/messages.md

This file was deleted.

0 comments on commit eb9dfe6

Please sign in to comment.