Skip to content

Commit

Permalink
Merge branch 'main' into collin/v8-migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrit committed Oct 8, 2024
2 parents 97d5a9a + 7d6fc3a commit b921658
Show file tree
Hide file tree
Showing 62 changed files with 7,027 additions and 51 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ jobs:
"CellarFees",
"Incentives",
"Pubsub",
"Addresses",
]
steps:
- name: Set up Go 1.22
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ test-docker-push: test-docker
###############################################################################
### Protobuf ###
###############################################################################
protoVer=0.13.1
protoVer=0.15.1
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

proto-all: proto-format proto-lint proto-gen

proto-gen:
@echo "Generating Protobuf files"
# todo: figure out why this old method was failing
Expand Down Expand Up @@ -391,6 +391,9 @@ e2e_incentives_test: e2e_clean_slate
e2e_pubsub_test: e2e_clean_slate
@E2E_SKIP_CLEANUP=true integration_tests/integration_tests.test -test.failfast -test.v -test.run IntegrationTestSuite -testify.m TestPubsub || make -s fail

e2e_addresses_test: e2e_clean_slate
@E2E_SKIP_CLEANUP=true integration_tests/integration_tests.test -test.failfast -test.v -test.run IntegrationTestSuite -testify.m TestAddresses || make -s fail

fail:
@echo 'test failed; dumping container logs into ./testlogs for review'
@docker logs ethereum > testlogs/ethereum.log 2>&1 || true
Expand Down
19 changes: 18 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ import (
gravitytypes "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types"
appParams "github.com/peggyjv/sommelier/v7/app/params"
v8 "github.com/peggyjv/sommelier/v7/app/upgrades/v8"
"github.com/peggyjv/sommelier/v7/x/addresses"
addresseskeeper "github.com/peggyjv/sommelier/v7/x/addresses/keeper"
addressestypes "github.com/peggyjv/sommelier/v7/x/addresses/types"
"github.com/peggyjv/sommelier/v7/x/auction"
auctionclient "github.com/peggyjv/sommelier/v7/x/auction/client"
auctionkeeper "github.com/peggyjv/sommelier/v7/x/auction/keeper"
Expand Down Expand Up @@ -202,6 +205,7 @@ var (
incentives.AppModuleBasic{},
auction.AppModuleBasic{},
pubsub.AppModuleBasic{},
addresses.AppModuleBasic{},
)

// module account permissions
Expand All @@ -218,8 +222,9 @@ var (
cellarfeestypes.ModuleName: nil,
incentivestypes.ModuleName: nil,
axelarcorktypes.ModuleName: nil,
auctiontypes.ModuleName: nil,
auctiontypes.ModuleName: {authtypes.Burner},
pubsubtypes.ModuleName: nil,
addressestypes.ModuleName: nil,
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -277,6 +282,7 @@ type SommelierApp struct {
IncentivesKeeper incentiveskeeper.Keeper
AuctionKeeper auctionkeeper.Keeper
PubsubKeeper pubsubkeeper.Keeper
AddressesKeeper addresseskeeper.Keeper

// make capability scoped keepers public for test purposes (IBC only)
ScopedAxelarCorkKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -344,6 +350,7 @@ func NewSommelierApp(
auctiontypes.StoreKey,
cellarfeestypes.StoreKey,
pubsubtypes.StoreKey,
addressestypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -525,6 +532,10 @@ func NewSommelierApp(
app.CorkKeeper.Hooks(),
))

app.AddressesKeeper = *addresseskeeper.NewKeeper(
appCodec, keys[addressestypes.StoreKey], app.GetSubspace(addressestypes.ModuleName),
)

// register the proposal types
govRouter := govtypesv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govtypesv1beta1.ProposalHandler).
Expand Down Expand Up @@ -605,6 +616,7 @@ func NewSommelierApp(
cellarfees.NewAppModule(app.CellarFeesKeeper, appCodec, app.AccountKeeper, app.BankKeeper, app.MintKeeper, app.CorkKeeper, app.AuctionKeeper),
auction.NewAppModule(app.AuctionKeeper, app.BankKeeper, app.AccountKeeper, appCodec),
pubsub.NewAppModule(appCodec, app.PubsubKeeper, app.StakingKeeper, app.GravityKeeper),
addresses.NewAppModule(appCodec, app.AddressesKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -639,6 +651,7 @@ func NewSommelierApp(
cellarfeestypes.ModuleName,
auctiontypes.ModuleName,
pubsubtypes.ModuleName,
addressestypes.ModuleName,
)

// NOTE gov must come before staking
Expand Down Expand Up @@ -669,6 +682,7 @@ func NewSommelierApp(
cellarfeestypes.ModuleName,
auctiontypes.ModuleName,
pubsubtypes.ModuleName,
addressestypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -707,6 +721,7 @@ func NewSommelierApp(
cellarfeestypes.ModuleName,
auctiontypes.ModuleName,
pubsubtypes.ModuleName,
addressestypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -742,6 +757,7 @@ func NewSommelierApp(
cellarfees.NewAppModule(app.CellarFeesKeeper, appCodec, app.AccountKeeper, app.BankKeeper, app.MintKeeper, app.CorkKeeper, app.AuctionKeeper),
auction.NewAppModule(app.AuctionKeeper, app.BankKeeper, app.AccountKeeper, appCodec),
pubsub.NewAppModule(appCodec, app.PubsubKeeper, app.StakingKeeper, app.GravityKeeper),
addresses.NewAppModule(appCodec, app.AddressesKeeper),
)

app.sm.RegisterStoreDecoders()
Expand Down Expand Up @@ -993,6 +1009,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(incentivestypes.ModuleName)
paramsKeeper.Subspace(auctiontypes.ModuleName)
paramsKeeper.Subspace(pubsubtypes.ModuleName)
paramsKeeper.Subspace(addressestypes.ModuleName)

return paramsKeeper
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/peggyjv/sommelier/v7

go 1.22

toolchain go1.22.2
toolchain go1.22.1

require (
cosmossdk.io/api v0.3.1
Expand Down
145 changes: 145 additions & 0 deletions integration_tests/addresses_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package integration_tests

import (
"context"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/peggyjv/sommelier/v7/x/addresses/types"
)

func (s *IntegrationTestSuite) TestAddresses() {
s.Run("Bring up chain, submit, query, and remove address mappings", func() {
s.T().Log("Starting x/addresses tests")
val := s.chain.validators[0]
kb, err := val.keyring()
s.Require().NoError(err)
val0ClientCtx, err := s.chain.clientContext("tcp://localhost:26657", &kb, "val", val.address())
s.Require().NoError(err)
addressesQueryClient := types.NewQueryClient(val0ClientCtx)

orch := s.chain.orchestrators[0]
orchClientCtx, err := s.chain.clientContext("tcp://localhost:26657", orch.keyring, "orch", orch.address())
s.Require().NoError(err)

evmAddress := common.HexToAddress("0x1234567890123456789012345678901234567890")
cosmosAddress := orch.address()

addAddressMappingMsg, err := types.NewMsgAddAddressMapping(evmAddress, cosmosAddress)
s.Require().NoError(err)

s.T().Logf("Submitting mapping from %s to %s", evmAddress.Hex(), cosmosAddress.String())
_, err = s.chain.sendMsgs(*orchClientCtx, addAddressMappingMsg)
s.Require().NoError(err)

s.T().Log("Testing queries return expected addresses")
s.Require().Eventually(func() bool {
queryRes, err := addressesQueryClient.QueryAddressMappings(context.Background(), &types.QueryAddressMappingsRequest{})
if err != nil {
s.T().Logf("Error querying address mappings: %s", err)
return false
}

return len(queryRes.AddressMappings) == 1 && evmAddress.Hex() == queryRes.AddressMappings[0].EvmAddress
}, 20*time.Second, 4*time.Second, "address mapping never found")

queryByEvmRes, err := addressesQueryClient.QueryAddressMappingByEVMAddress(context.Background(), &types.QueryAddressMappingByEVMAddressRequest{EvmAddress: evmAddress.Hex()})
s.Require().NoError(err)
s.Require().Equal(cosmosAddress.String(), queryByEvmRes.CosmosAddress, "Cosmos address does not match")
s.Require().Equal(evmAddress.Hex(), queryByEvmRes.EvmAddress, "EVM address does not match")

queryByCosmosRes, err := addressesQueryClient.QueryAddressMappingByCosmosAddress(context.Background(), &types.QueryAddressMappingByCosmosAddressRequest{CosmosAddress: cosmosAddress.String()})
s.Require().NoError(err)
s.Require().Equal(cosmosAddress.String(), queryByCosmosRes.CosmosAddress, "Cosmos address does not match")
s.Require().Equal(evmAddress.Hex(), queryByCosmosRes.EvmAddress, "EVM address does not match")

s.T().Log("Removing address mapping")
removeAddressMappingMsg, err := types.NewMsgRemoveAddressMapping(cosmosAddress)
s.Require().NoError(err)

_, err = s.chain.sendMsgs(*orchClientCtx, removeAddressMappingMsg)
s.Require().NoError(err)

s.T().Log("Testing mappings query returns no addresses")
s.Require().Eventually(func() bool {
queryRes, err := addressesQueryClient.QueryAddressMappings(context.Background(), &types.QueryAddressMappingsRequest{})
if err != nil {
s.T().Logf("Error querying address mappings: %s", err)
return false
}

return len(queryRes.AddressMappings) == 0
}, 20*time.Second, 4*time.Second, "address mapping not deleted")

_, err = addressesQueryClient.QueryAddressMappingByEVMAddress(context.Background(), &types.QueryAddressMappingByEVMAddressRequest{EvmAddress: evmAddress.Hex()})
s.Require().Error(err)
s.Require().Contains(err.Error(), "code = NotFound")

_, err = addressesQueryClient.QueryAddressMappingByCosmosAddress(context.Background(), &types.QueryAddressMappingByCosmosAddressRequest{CosmosAddress: cosmosAddress.String()})
s.Require().Error(err)
s.Require().Contains(err.Error(), "code = NotFound")

// Test error cases

// Test adding multiple mappings
s.T().Log("Adding multiple mappings")
evmAddress2 := common.HexToAddress("0x2345678901234567890123456789012345678901")
cosmosAddress2 := s.chain.orchestrators[1].address()
orch1 := s.chain.orchestrators[1]
orch1ClientCtx, err := s.chain.clientContext("tcp://localhost:26657", orch1.keyring, "orch", orch1.address())
s.Require().NoError(err)

addAddressMappingMsg2, err := types.NewMsgAddAddressMapping(evmAddress2, cosmosAddress2)
s.Require().NoError(err)

_, err = s.chain.sendMsgs(*orchClientCtx, addAddressMappingMsg)
s.Require().NoError(err)
_, err = s.chain.sendMsgs(*orch1ClientCtx, addAddressMappingMsg2)
s.Require().NoError(err)

// Query multiple mappings
s.T().Log("Querying multiple mappings")
s.Require().Eventually(func() bool {
queryRes, err := addressesQueryClient.QueryAddressMappings(context.Background(), &types.QueryAddressMappingsRequest{})
if err != nil {
s.T().Logf("Error querying address mappings: %s", err)
return false
}

return len(queryRes.AddressMappings) == 2
}, 20*time.Second, 4*time.Second, "expected two address mappings")

// Test adding a duplicate mapping
s.T().Log("Adding a duplicate mapping")
duplicateMsg, err := types.NewMsgAddAddressMapping(evmAddress, cosmosAddress)
s.Require().NoError(err)

_, err = s.chain.sendMsgs(*orchClientCtx, duplicateMsg)
s.Require().NoError(err)
_, err = s.chain.sendMsgs(*orchClientCtx, duplicateMsg)
s.Require().NoError(err)

// Test removing a non-existent mapping
s.T().Log("Removing a non-existent mapping")
nonExistentAddress := s.chain.orchestrators[2].address()
orch2 := s.chain.orchestrators[2]
orch2ClientCtx, err := s.chain.clientContext("tcp://localhost:26657", orch2.keyring, "orch", orch2.address())
s.Require().NoError(err)
removeNonExistentMsg, err := types.NewMsgRemoveAddressMapping(nonExistentAddress)
s.Require().NoError(err)

_, err = s.chain.sendMsgs(*orch2ClientCtx, removeNonExistentMsg)
s.Require().NoError(err)

// Test querying with invalid addresses
s.T().Log("Querying with invalid addresses")
_, err = addressesQueryClient.QueryAddressMappingByEVMAddress(context.Background(), &types.QueryAddressMappingByEVMAddressRequest{EvmAddress: "invalid"})
s.Require().Error(err)
s.Require().Contains(err.Error(), "invalid EVM address")

s.T().Log("Querying with invalid cosmos address")
_, err = addressesQueryClient.QueryAddressMappingByCosmosAddress(context.Background(), &types.QueryAddressMappingByCosmosAddressRequest{CosmosAddress: "invalid"})
s.Require().Error(err)
s.Require().Contains(err.Error(), "failed to parse cosmos address")
})
}
37 changes: 36 additions & 1 deletion integration_tests/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func (s *IntegrationTestSuite) TestAuction() {
s.Require().NoError(err)
auctionQueryClient := types.NewQueryClient(val0ClientCtx)

// Query the total supply of usomm before the auction
bankQueryClient := banktypes.NewQueryClient(val0ClientCtx)
supplyRes, err := bankQueryClient.SupplyOf(context.Background(), &banktypes.QuerySupplyOfRequest{Denom: testDenom})
s.Require().NoError(err)

// Verify auction created for testing exists
auctionQuery := types.QueryActiveAuctionRequest{
AuctionId: uint32(1),
Expand Down Expand Up @@ -115,7 +120,6 @@ func (s *IntegrationTestSuite) TestAuction() {
}, time.Second*30, time.Second*5, "proposal was never accepted")
s.T().Log("Proposal approved!")

bankQueryClient := banktypes.NewQueryClient(val0ClientCtx)
balanceRes, err := bankQueryClient.AllBalances(context.Background(), &banktypes.QueryAllBalancesRequest{Address: authtypes.NewModuleAddress(types.ModuleName).String()})
s.Require().NoError(err)
s.T().Logf("Auction module token balances before bids %v", balanceRes.Balances)
Expand Down Expand Up @@ -293,6 +297,37 @@ func (s *IntegrationTestSuite) TestAuction() {
s.Require().Equal(expectedEndedAuction, *endedAuctionResponse.Auction)
s.T().Log("Ended auction stored correctly!")

s.T().Log("Verifying cellarfees module account balance...")
cellarfeesModuleAddress := authtypes.NewModuleAddress(cellarfees.ModuleName).String()
cellarfeesBalanceRes, err := bankQueryClient.AllBalances(context.Background(), &banktypes.QueryAllBalancesRequest{Address: cellarfeesModuleAddress})
s.Require().NoError(err)

totalSommPaid := expectedBid1.TotalUsommPaid.Amount.Add(expectedBid2.TotalUsommPaid.Amount)
// default burn rate is 0.5 so 50% of the SOMM paid to the cellarfees module account
expectedCellarfeesSomm := totalSommPaid.Quo(sdk.NewInt(2))

found, cellarfeesSommBalance := balanceOfDenom(cellarfeesBalanceRes.Balances, testDenom)
s.Require().True(found, "SOMM balance not present in cellarfees module account")
s.Require().GreaterOrEqual(expectedCellarfeesSomm.Int64(), cellarfeesSommBalance.Amount.Int64(), "Cellarfees module account should have 50% or less of the SOMM received from the auction (less if distributions have occurred)")
s.T().Log("Cellarfees module account balance verified correctly!")

s.T().Log("Verifying total supply of usomm has been reduced...")

// Calculate the expected burn amount (50% of total SOMM paid in auction)
expectedBurnAmount := totalSommPaid.Quo(sdk.NewInt(2))

// Calculate the expected new total supply
expectedNewSupply := supplyRes.Amount.Amount.Sub(expectedBurnAmount)

// Query the actual new total supply
newSupplyRes, err := bankQueryClient.SupplyOf(context.Background(), &banktypes.QuerySupplyOfRequest{Denom: testDenom})
s.Require().NoError(err)

// Verify that the new supply matches the expected new supply
s.Require().Equal(expectedNewSupply.Int64(), newSupplyRes.Amount.Amount.Int64(), "Total supply of usomm should be reduced by the amount burnt")

s.T().Log("Total supply of usomm has been correctly reduced!")

s.T().Log("--Test completed successfully--")
})
}
Expand Down
7 changes: 7 additions & 0 deletions integration_tests/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
gravitytypes "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types"
"github.com/peggyjv/sommelier/v7/app/params"
addressestypes "github.com/peggyjv/sommelier/v7/x/addresses/types"
auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types"
axelarcorktypes "github.com/peggyjv/sommelier/v7/x/axelarcork/types"
cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types"
Expand Down Expand Up @@ -414,6 +415,7 @@ func (s *IntegrationTestSuite) initGenesis() {
// Add an auction for integration testing of the auction module
var auctionGenState auctiontypes.GenesisState
s.Require().NoError(cdc.UnmarshalJSON(appGenState[auctiontypes.ModuleName], &auctionGenState))
auctionGenState.Params = auctiontypes.DefaultParams()
auctionGenState.TokenPrices = append(auctionGenState.TokenPrices, &auctiontypes.TokenPrice{
Denom: testDenom,
Exponent: 6,
Expand Down Expand Up @@ -482,6 +484,11 @@ func (s *IntegrationTestSuite) initGenesis() {
s.Require().NoError(err)
appGenState[pubsubtypes.ModuleName] = bz

// set addresses gen state
addressesGenState := addressestypes.DefaultGenesisState()
s.Require().NoError(cdc.UnmarshalJSON(appGenState[addressestypes.ModuleName], &addressesGenState))
appGenState[addressestypes.ModuleName] = cdc.MustMarshalJSON(&addressesGenState)

// generate genesis txs
genTxs := make([]json.RawMessage, len(s.chain.validators))
for i, val := range s.chain.validators {
Expand Down
10 changes: 10 additions & 0 deletions proto/addresses/v1/addresses.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";
package addresses.v1;

option go_package = "github.com/peggyjv/sommelier/v7/x/addresses/types";

message AddressMapping {
string cosmos_address = 1;
string evm_address = 2;
}

Loading

0 comments on commit b921658

Please sign in to comment.