Skip to content

Commit

Permalink
feat(rollapp): query for genesis bridge validation (#1564)
Browse files Browse the repository at this point in the history
Co-authored-by: danwt <[email protected]>
  • Loading branch information
keruch and danwt authored Nov 28, 2024
1 parent 65cd290 commit 62fe71c
Show file tree
Hide file tree
Showing 12 changed files with 949 additions and 391 deletions.
28 changes: 13 additions & 15 deletions ibctesting/genesis_bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ import (
"time"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/dymensionxyz/dymension/v3/testutil/sample"
irotypes "github.com/dymensionxyz/dymension/v3/x/iro/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp/genesisbridge"
rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
"github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/dymension/v3/app/apptesting"
appparams "github.com/dymensionxyz/dymension/v3/app/params"
"github.com/stretchr/testify/suite"

"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
"github.com/dymensionxyz/dymension/v3/testutil/sample"
irotypes "github.com/dymensionxyz/dymension/v3/x/iro/types"
rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

var successAck = channeltypes.CommitAcknowledgement(channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement())
Expand Down Expand Up @@ -232,7 +230,7 @@ func (s *transferGenesisSuite) TestInvalidGenesisDenomMetadata() {
rollapp := s.hubApp().RollappKeeper.MustGetRollapp(s.hubCtx(), rollappChainID())

packet := s.genesisBridgePacket(rollapp.GenesisInfo)
var gb genesisbridge.GenesisBridgeData
var gb rollapptypes.GenesisBridgeData
err := json.Unmarshal(packet.Data, &gb)
s.Require().NoError(err)

Expand Down Expand Up @@ -277,7 +275,7 @@ func (s *transferGenesisSuite) TestInvalidGenesisTransfer() {
packet := s.genesisBridgePacket(rollapp.GenesisInfo)

// change the amount in the genesis transfer
var gb genesisbridge.GenesisBridgeData
var gb rollapptypes.GenesisBridgeData
err := json.Unmarshal(packet.Data, &gb)
s.Require().NoError(err)
gb.GenesisTransfer.Amount = "1242353645"
Expand Down Expand Up @@ -366,7 +364,7 @@ func (s *transferGenesisSuite) genesisBridgePacket(raGenesisInfo rollapptypes.Ge
display := raGenesisInfo.NativeDenom.Display
initialSupply := raGenesisInfo.InitialSupply

var gb genesisbridge.GenesisBridgeData
var gb rollapptypes.GenesisBridgeData

meta := banktypes.Metadata{
DenomUnits: []*banktypes.DenomUnit{
Expand All @@ -385,7 +383,7 @@ func (s *transferGenesisSuite) genesisBridgePacket(raGenesisInfo rollapptypes.Ge
}
s.Require().NoError(meta.Validate()) // sanity check the test is written correctly

gb.GenesisInfo = genesisbridge.GenesisBridgeInfo{
gb.GenesisInfo = rollapptypes.GenesisBridgeInfo{
GenesisChecksum: "checksum",
Bech32Prefix: "ethm",
NativeDenom: rollapptypes.DenomMetadata{
Expand All @@ -405,7 +403,7 @@ func (s *transferGenesisSuite) genesisBridgePacket(raGenesisInfo rollapptypes.Ge
denom,
raGenesisInfo.GenesisTransferAmount().String(),
s.rollappChain().SenderAccount.GetAddress().String(),
genesisbridge.HubRecipient,
rollapptypes.HubRecipient,
"",
)
gb.GenesisTransfer = &gTransfer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
package dymensionxyz.dymension.genesisbridge;
package dymensionxyz.dymension.rollapp;

import "gogoproto/gogo.proto";
import "cosmos/bank/v1beta1/bank.proto";
Expand All @@ -8,7 +8,7 @@ import "dymensionxyz/dymension/rollapp/metadata.proto";
import "dymensionxyz/dymension/rollapp/genesis_info.proto";


option go_package = "github.com/dymensionxyz/dymension/v3/x/rollapp/genesisbridge";
option go_package = "github.com/dymensionxyz/dymension/v3/x/rollapp/types";

// GenesisBridgeData is the data struct that is passed to the hub for the
// genesis bridge flow
Expand All @@ -30,12 +30,12 @@ message GenesisBridgeInfo {
// unique bech32 prefix
string bech32_prefix = 2;
// native_denom is the base denom for the native token
rollapp.DenomMetadata native_denom = 3 [ (gogoproto.nullable) = false ];
DenomMetadata native_denom = 3 [ (gogoproto.nullable) = false ];
// initial_supply is the initial supply of the native token
string initial_supply = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// accounts on the Hub to fund with some bootstrapping transfers
repeated rollapp.GenesisAccount genesis_accounts = 5 [ (gogoproto.nullable) = false ];
repeated GenesisAccount genesis_accounts = 5 [ (gogoproto.nullable) = false ];
}
14 changes: 14 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "dymensionxyz/dymension/rollapp/params.proto";
import "dymensionxyz/dymension/rollapp/rollapp.proto";
import "dymensionxyz/dymension/rollapp/state_info.proto";
import "dymensionxyz/dymension/rollapp/app.proto";
import "dymensionxyz/dymension/rollapp/genesis_bridge_data.proto";

// Query defines the gRPC querier service.
service Query {
Expand Down Expand Up @@ -64,6 +65,9 @@ service Query {
rpc ObsoleteDRSVersions(QueryObsoleteDRSVersionsRequest) returns (QueryObsoleteDRSVersionsResponse) {
option (google.api.http).get = "/dymensionxyz/dymension/rollapp/obsolete_drs_versions";
}

// Validates provided genesis bridge data against the hub.
rpc ValidateGenesisBridge(QueryValidateGenesisBridgeRequest) returns (QueryValidateGenesisBridgeResponse);
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -147,3 +151,13 @@ message QueryObsoleteDRSVersionsRequest {}
message QueryObsoleteDRSVersionsResponse {
repeated uint32 drs_versions = 1;
}

message QueryValidateGenesisBridgeRequest {
string rollappId = 1;
GenesisBridgeData data = 2 [ (gogoproto.nullable) = false ];
}

message QueryValidateGenesisBridgeResponse {
bool valid = 1;
string err = 2;
}
75 changes: 0 additions & 75 deletions x/rollapp/genesisbridge/genesis_bridge_data.go

This file was deleted.

62 changes: 0 additions & 62 deletions x/rollapp/genesisbridge/genesis_transfer.go

This file was deleted.

Loading

0 comments on commit 62fe71c

Please sign in to comment.