diff --git a/demo/go.mod b/demo/go.mod index 3260d84..3cbc29f 100644 --- a/demo/go.mod +++ b/demo/go.mod @@ -59,7 +59,7 @@ require ( filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect - github.com/CosmWasm/wasmvm/v2 v2.0.0 // indirect + github.com/CosmWasm/wasmvm/v2 v2.0.3 // indirect github.com/DataDog/datadog-go v3.2.0+incompatible // indirect github.com/DataDog/zstd v1.5.5 // indirect github.com/aws/aws-sdk-go v1.44.312 // indirect diff --git a/demo/go.sum b/demo/go.sum index 97cd621..fbc97f4 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -225,8 +225,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CosmWasm/wasmd v0.51.0 h1:3A2o20RrdF7P1D3Xb+R7A/pHbbHWsYCDXrHLa7S0SC8= github.com/CosmWasm/wasmd v0.51.0/go.mod h1:7TSaj5HoolghujuVWeExqmcUKgpcYWEySGLSODbnnwY= -github.com/CosmWasm/wasmvm/v2 v2.0.0 h1:IqNCI2G0mvs7K6ej17/I28805rVqnu+Y1cWDqIdwb08= -github.com/CosmWasm/wasmvm/v2 v2.0.0/go.mod h1:su9lg5qLr7adV95eOfzjZWkGiky8WNaNIHDr7Fpu7Ck= +github.com/CosmWasm/wasmvm/v2 v2.0.3 h1:G9jpwDk+qFUfDkXCigpWPn9JTGM0H7egKzWQnMEONwE= +github.com/CosmWasm/wasmvm/v2 v2.0.3/go.mod h1:su9lg5qLr7adV95eOfzjZWkGiky8WNaNIHDr7Fpu7Ck= github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= diff --git a/go.work.sum b/go.work.sum index 38a2eaa..e6bf3e3 100644 --- a/go.work.sum +++ b/go.work.sum @@ -137,8 +137,6 @@ cloud.google.com/go/webrisk v1.9.5/go.mod h1:aako0Fzep1Q714cPEM5E+mtYX8/jsfegAuS cloud.google.com/go/websecurityscanner v1.6.5/go.mod h1:QR+DWaxAz2pWooylsBF854/Ijvuoa3FCyS1zBa1rAVQ= cloud.google.com/go/workflows v1.12.4/go.mod h1:yQ7HUqOkdJK4duVtMeBCAOPiN1ZF1E9pAMX51vpwB/w= cosmossdk.io/api v0.7.2/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= -cosmossdk.io/api v0.7.5 h1:eMPTReoNmGUm8DeiQL9DyM8sYDjEhWzL1+nLbI9DqtQ= -cosmossdk.io/api v0.7.5/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= cosmossdk.io/errors v1.0.0/go.mod h1:+hJZLuhdDE0pYN8HkOrVNwrIOYvUGnn6+4fjnJs/oV0= cosmossdk.io/log v1.2.0/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4= cosmossdk.io/log v1.2.1/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4= @@ -162,6 +160,8 @@ github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EF github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno= github.com/CloudyKit/jet v2.1.3-0.20180809161101-62edd43e4f88+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w= github.com/CloudyKit/jet/v6 v6.2.0/go.mod h1:d3ypHeIRNo2+XyqnGA8s+aphtcVpjP5hPwP/Lzo7Ro4= +github.com/CosmWasm/wasmvm/v2 v2.0.3 h1:G9jpwDk+qFUfDkXCigpWPn9JTGM0H7egKzWQnMEONwE= +github.com/CosmWasm/wasmvm/v2 v2.0.3/go.mod h1:su9lg5qLr7adV95eOfzjZWkGiky8WNaNIHDr7Fpu7Ck= github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= @@ -262,14 +262,10 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfc github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= github.com/cosmos/cosmos-sdk v0.50.1/go.mod h1:fsLSPGstCwn6MMsFDMAQWGJj8E4sYsN9Gnu1bGE5imA= -github.com/cosmos/cosmos-sdk v0.50.7 h1:LsBGKxifENR/DN4E1RZaitsyL93HU44x0p8EnMHp4V4= -github.com/cosmos/cosmos-sdk v0.50.7/go.mod h1:84xDDJEHttRT7NDGwBaUOLVOMN0JNE9x7NbsYIxXs1s= github.com/cosmos/gogoproto v1.4.3/go.mod h1:0hLIG5TR7IvV1fme1HCFKjfzW9X2x0Mo+RooWXCnOWU= github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSohtaxzQnYq1Y= github.com/cosmos/iavl v1.0.0/go.mod h1:CmTGqMnRnucjxbjduneZXT+0vPgNElYvdefjX2q9tYc= github.com/cosmos/iavl v1.1.1/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM= -github.com/cosmos/ibc-go/v8 v8.3.2 h1:8X1oHHKt2Bh9hcExWS89rntLaCKZp2EjFTUSxKlPhGI= -github.com/cosmos/ibc-go/v8 v8.3.2/go.mod h1:WVVIsG39jGrF9Cjggjci6LzySyWGloz194sjTxiGNIE= github.com/cosmos/relayer/v2 v2.5.1/go.mod h1:KygWPbGY9ley9Q42CMg5uzmrf4BIe+EfxU5j44xrLRQ= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= diff --git a/tests/e2e/go.mod b/tests/e2e/go.mod index 953b3aa..0bbcfcc 100644 --- a/tests/e2e/go.mod +++ b/tests/e2e/go.mod @@ -61,7 +61,7 @@ require ( filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect - github.com/CosmWasm/wasmvm/v2 v2.0.1 // indirect + github.com/CosmWasm/wasmvm/v2 v2.0.3 // indirect github.com/DataDog/datadog-go v3.2.0+incompatible // indirect github.com/DataDog/zstd v1.5.5 // indirect github.com/aead/siphash v1.0.1 // indirect diff --git a/tests/e2e/go.sum b/tests/e2e/go.sum index 1b4c5b1..075c3fa 100644 --- a/tests/e2e/go.sum +++ b/tests/e2e/go.sum @@ -223,8 +223,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CosmWasm/wasmd v0.51.0 h1:3A2o20RrdF7P1D3Xb+R7A/pHbbHWsYCDXrHLa7S0SC8= github.com/CosmWasm/wasmd v0.51.0/go.mod h1:7TSaj5HoolghujuVWeExqmcUKgpcYWEySGLSODbnnwY= -github.com/CosmWasm/wasmvm/v2 v2.0.1 h1:0YCQ7MKGNri7NFeRp75erPJXrqyCtH4gdc9jMstyMzk= -github.com/CosmWasm/wasmvm/v2 v2.0.1/go.mod h1:su9lg5qLr7adV95eOfzjZWkGiky8WNaNIHDr7Fpu7Ck= +github.com/CosmWasm/wasmvm/v2 v2.0.3 h1:G9jpwDk+qFUfDkXCigpWPn9JTGM0H7egKzWQnMEONwE= +github.com/CosmWasm/wasmvm/v2 v2.0.3/go.mod h1:su9lg5qLr7adV95eOfzjZWkGiky8WNaNIHDr7Fpu7Ck= github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= diff --git a/tests/e2e/main_test.go b/tests/e2e/main_test.go index 56262d2..b679a4a 100644 --- a/tests/e2e/main_test.go +++ b/tests/e2e/main_test.go @@ -93,20 +93,38 @@ func (s *BabylonSDKTestSuite) Test1ContractDeployment() { s.NoError(err) s.Equal(adminResp["admin"], s.ConsumerCli.GetSender().String()) + // get Babylon contract address + babylonContractAddress := s.ConsumerContract.Babylon.String() + btcStakingContractAddress := s.ConsumerContract.BTCStaking.String() + // 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(), + BabylonContractAddress: babylonContractAddress, + BtcStakingContractAddress: btcStakingContractAddress, }, } s.ConsumerCli.MustExecGovProposal(msgUpdateParams) + + // assert the contract addresses are updated + params := s.ConsumerApp.BabylonKeeper.GetParams(s.ConsumerChain.GetContext()) + s.Equal(babylonContractAddress, params.BabylonContractAddress) + s.Equal(btcStakingContractAddress, params.BtcStakingContractAddress) } // TestExample is an example test case func (s *BabylonSDKTestSuite) Test2MockConsumerFpDelegation() { + // generate headers + headersMsg := types.GenBTCHeadersMsg() + headersMsgBytes, err := json.Marshal(headersMsg) + s.NoError(err) + // send headers to the Babylon contract. This is to ensure that the contract is + // indexing BTC headers correctly. + res, err := s.ConsumerCli.Exec(s.ConsumerContract.Babylon, headersMsgBytes) + s.NoError(err, res) + testMsg = types.GenExecMessage() msgBytes, err := json.Marshal(testMsg) s.NoError(err) diff --git a/tests/e2e/types/datagen.go b/tests/e2e/types/datagen.go index e463bac..b306aa0 100644 --- a/tests/e2e/types/datagen.go +++ b/tests/e2e/types/datagen.go @@ -14,9 +14,34 @@ import ( "github.com/stretchr/testify/require" ) +func GenBTCHeadersMsg() BabylonExecuteMsg { + r := rand.New(rand.NewSource(time.Now().Unix())) + + chain := datagen.NewBTCHeaderChainWithLength(r, 0, 0, 10) + headers := []BtcHeader{} + for _, header := range chain.Headers { + headers = append(headers, BtcHeader{ + Version: header.Version, + PrevBlockhash: header.PrevBlock.String(), + MerkleRoot: header.MerkleRoot.String(), + Time: uint32(header.Timestamp.Unix()), + Bits: header.Bits, + Nonce: header.Nonce, + }) + } + + return BabylonExecuteMsg{ + BtcHeaders: BTCHeadersMsg{ + Headers: headers, + }, + } +} + func GenExecMessage() ExecuteMessage { _, newDel := genBTCDelegation() + addr := datagen.GenRandomAccount().Address + newFp := NewFinalityProvider{ Description: &FinalityProviderDescription{ Moniker: "fp1", @@ -26,13 +51,10 @@ func GenExecMessage() ExecuteMessage { Details: "details", }, Commission: "0.05", - BabylonPK: &PubKey{ - Key: base64.StdEncoding.EncodeToString([]byte("mock_pub_rand")), - }, - BTCPKHex: newDel.FpBtcPkList[0], - Pop: &ProofOfPossession{ + Addr: addr, + BTCPKHex: newDel.FpBtcPkList[0], + Pop: &ProofOfPossessionBtc{ BTCSigType: 0, - BabylonSig: base64.StdEncoding.EncodeToString([]byte("mock_pub_rand")), BTCSig: base64.StdEncoding.EncodeToString([]byte("mock_pub_rand")), }, ConsumerID: "osmosis-1", @@ -158,6 +180,7 @@ func convertBTCDelegationToActiveBtcDelegation(mockDel *bstypes.BTCDelegation) A } return ActiveBtcDelegation{ + StakerAddr: mockDel.StakerAddr, BTCPkHex: mockDel.BtcPk.MarshalHex(), FpBtcPkList: fpBtcPkList, StartHeight: mockDel.StartHeight, @@ -177,9 +200,9 @@ func convertBTCDelegationToActiveBtcDelegation(mockDel *bstypes.BTCDelegation) A type NewFinalityProvider struct { Description *FinalityProviderDescription `json:"description,omitempty"` Commission string `json:"commission"` - BabylonPK *PubKey `json:"babylon_pk,omitempty"` + Addr string `json:"addr,omitempty"` BTCPKHex string `json:"btc_pk_hex"` - Pop *ProofOfPossession `json:"pop,omitempty"` + Pop *ProofOfPossessionBtc `json:"pop,omitempty"` ConsumerID string `json:"consumer_id"` } @@ -191,13 +214,8 @@ type FinalityProviderDescription struct { Details string `json:"details"` } -type PubKey struct { - Key string `json:"key"` -} - -type ProofOfPossession struct { +type ProofOfPossessionBtc struct { BTCSigType int32 `json:"btc_sig_type"` - BabylonSig string `json:"babylon_sig"` BTCSig string `json:"btc_sig"` } @@ -221,6 +239,7 @@ type BtcUndelegationInfo struct { } type ActiveBtcDelegation struct { + StakerAddr string `json:"staker_addr"` BTCPkHex string `json:"btc_pk_hex"` FpBtcPkList []string `json:"fp_btc_pk_list"` StartHeight uint64 `json:"start_height"` @@ -244,6 +263,23 @@ type UnbondedBtcDelegation struct { // Define fields as needed } +type BabylonExecuteMsg struct { + BtcHeaders BTCHeadersMsg `json:"btc_headers"` +} + +type BTCHeadersMsg struct { + Headers []BtcHeader `json:"headers"` +} + +type BtcHeader struct { + Version int32 `json:"version"` + PrevBlockhash string `json:"prev_blockhash"` + MerkleRoot string `json:"merkle_root"` + Time uint32 `json:"time"` + Bits uint32 `json:"bits"` + Nonce uint32 `json:"nonce"` +} + type ExecuteMessage struct { BtcStaking BtcStaking `json:"btc_staking"` } diff --git a/tests/testdata/babylon_contract.wasm b/tests/testdata/babylon_contract.wasm index 5286295..d354561 100644 Binary files a/tests/testdata/babylon_contract.wasm and b/tests/testdata/babylon_contract.wasm differ diff --git a/tests/testdata/btc_staking.wasm b/tests/testdata/btc_staking.wasm index 71342a8..02877e0 100644 Binary files a/tests/testdata/btc_staking.wasm and b/tests/testdata/btc_staking.wasm differ diff --git a/tests/testdata/version.txt b/tests/testdata/version.txt index e0d30fb..bd5d36c 100644 --- a/tests/testdata/version.txt +++ b/tests/testdata/version.txt @@ -1 +1 @@ -v0.7.0-rc.2 +a8366f29816e0ea6665131f241d916ee59904524 diff --git a/x/go.mod b/x/go.mod index f94b04b..6ae5ff5 100644 --- a/x/go.mod +++ b/x/go.mod @@ -38,7 +38,7 @@ require ( cosmossdk.io/x/evidence v0.1.1 cosmossdk.io/x/feegrant v0.1.1 cosmossdk.io/x/upgrade v0.1.2 - github.com/CosmWasm/wasmvm/v2 v2.0.0 + github.com/CosmWasm/wasmvm/v2 v2.0.3 github.com/cometbft/cometbft v0.38.7 github.com/cosmos/cosmos-db v1.0.2 github.com/cosmos/ibc-go/modules/capability v1.0.0 diff --git a/x/go.sum b/x/go.sum index 04185f8..14f66a1 100644 --- a/x/go.sum +++ b/x/go.sum @@ -223,8 +223,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CosmWasm/wasmd v0.51.0 h1:3A2o20RrdF7P1D3Xb+R7A/pHbbHWsYCDXrHLa7S0SC8= github.com/CosmWasm/wasmd v0.51.0/go.mod h1:7TSaj5HoolghujuVWeExqmcUKgpcYWEySGLSODbnnwY= -github.com/CosmWasm/wasmvm/v2 v2.0.0 h1:IqNCI2G0mvs7K6ej17/I28805rVqnu+Y1cWDqIdwb08= -github.com/CosmWasm/wasmvm/v2 v2.0.0/go.mod h1:su9lg5qLr7adV95eOfzjZWkGiky8WNaNIHDr7Fpu7Ck= +github.com/CosmWasm/wasmvm/v2 v2.0.3 h1:G9jpwDk+qFUfDkXCigpWPn9JTGM0H7egKzWQnMEONwE= +github.com/CosmWasm/wasmvm/v2 v2.0.3/go.mod h1:su9lg5qLr7adV95eOfzjZWkGiky8WNaNIHDr7Fpu7Ck= github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=