Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into top-of-block
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear committed Sep 25, 2023
2 parents e15fe01 + 705d983 commit e8966a8
Show file tree
Hide file tree
Showing 33 changed files with 479 additions and 184 deletions.
10 changes: 5 additions & 5 deletions cosmos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/cometbft/cometbft v0.38.0
github.com/cosmos/cosmos-db v1.0.0
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.50.0-rc.0.0.20230915171831-2196edacb99d
github.com/cosmos/cosmos-sdk v0.50.0-rc.0.0.20230925142031-19632293df2b
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.11
github.com/ethereum/go-ethereum v1.13.1
Expand All @@ -37,14 +37,14 @@ require (
github.com/onsi/gomega v1.27.10
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0 // indirect
github.com/tidwall/btree v1.7.0
github.com/tidwall/btree v1.7.0 // indirect
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect
google.golang.org/grpc v1.58.1
google.golang.org/protobuf v1.31.0
pkg.berachain.dev/polaris/contracts v0.0.0-20230919154905-0c53dfe1360a
pkg.berachain.dev/polaris/eth v0.0.0-20230919154905-0c53dfe1360a
pkg.berachain.dev/polaris/lib v0.0.0-20230919154905-0c53dfe1360a
pkg.berachain.dev/polaris/contracts v0.0.0-20230925142347-326426fa61f6
pkg.berachain.dev/polaris/eth v0.0.0-20230925142347-326426fa61f6
pkg.berachain.dev/polaris/lib v0.0.0-20230925142347-326426fa61f6
)

require github.com/spf13/cast v1.5.1
Expand Down
16 changes: 8 additions & 8 deletions cosmos/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.50.0-rc.0.0.20230915171831-2196edacb99d h1:dBD7O1D3lxfMwKjR71ooQanLzclJ17NZMHplL6qd8ZU=
github.com/cosmos/cosmos-sdk v0.50.0-rc.0.0.20230915171831-2196edacb99d/go.mod h1:8rNGga/Gg9/NIFvpqO4URts+8Cz/XVB0wTr5ZDm22UM=
github.com/cosmos/cosmos-sdk v0.50.0-rc.0.0.20230925142031-19632293df2b h1:RP4SQswWGtFkLWFJzlWa4iPfrL5SwEOum+0F85fCon8=
github.com/cosmos/cosmos-sdk v0.50.0-rc.0.0.20230925142031-19632293df2b/go.mod h1:8rNGga/Gg9/NIFvpqO4URts+8Cz/XVB0wTr5ZDm22UM=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
Expand Down Expand Up @@ -1492,12 +1492,12 @@ nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
pkg.berachain.dev/polaris/contracts v0.0.0-20230919154905-0c53dfe1360a h1:D8XJK/YnpTseGGETCA9ArU369nFTrYTYGsmofgN49G0=
pkg.berachain.dev/polaris/contracts v0.0.0-20230919154905-0c53dfe1360a/go.mod h1:pkgCryQfjPpCfmHJ7hEv6/0PoTwgG6uDc0cIQpMEBYg=
pkg.berachain.dev/polaris/eth v0.0.0-20230919154905-0c53dfe1360a h1:TAMeBYTswT2XHozvQXw8BTpP0hbaG4btnw8B03wuLz8=
pkg.berachain.dev/polaris/eth v0.0.0-20230919154905-0c53dfe1360a/go.mod h1:joeZS5xk3XFpcKlvA1YrETzc6MX6lGkbXZEL+ifKsiM=
pkg.berachain.dev/polaris/lib v0.0.0-20230919154905-0c53dfe1360a h1:cfaVkMfNtPr8UCrlpbpmjHJYsv18w+CVPhKg91Ng7NY=
pkg.berachain.dev/polaris/lib v0.0.0-20230919154905-0c53dfe1360a/go.mod h1:Qe/PmVj+gplJrsJsmdcWFTHw+DyraM67wk9nqFMnHmk=
pkg.berachain.dev/polaris/contracts v0.0.0-20230925142347-326426fa61f6 h1:U5wpPv/ZitKJCZkHWVsWOzAfX3orlnHHhn5rYGJ1DPA=
pkg.berachain.dev/polaris/contracts v0.0.0-20230925142347-326426fa61f6/go.mod h1:aM6e6GYmu5YPNUWGs0Qy3pL8N5MsRHO3QvcUruwF2Rc=
pkg.berachain.dev/polaris/eth v0.0.0-20230925142347-326426fa61f6 h1:0dIN2V+giVZmUOPvDyOxnXfTgZIoBOqjZTpXn704edY=
pkg.berachain.dev/polaris/eth v0.0.0-20230925142347-326426fa61f6/go.mod h1:XDIlhb6eOL2Rq81b0OPzke5IFQyqgbD7f60NRomcmXc=
pkg.berachain.dev/polaris/lib v0.0.0-20230925142347-326426fa61f6 h1:ZvjvAvaPEZr+Og4GABn1AGM7RPD6lIW12j3qouVDFvI=
pkg.berachain.dev/polaris/lib v0.0.0-20230925142347-326426fa61f6/go.mod h1:Qe/PmVj+gplJrsJsmdcWFTHw+DyraM67wk9nqFMnHmk=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
Expand Down
25 changes: 22 additions & 3 deletions cosmos/precompile/bank/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
generated "pkg.berachain.dev/polaris/contracts/bindings/cosmos/precompile/bank"
"pkg.berachain.dev/polaris/cosmos/precompile"
"pkg.berachain.dev/polaris/cosmos/precompile/bank"
"pkg.berachain.dev/polaris/cosmos/precompile/testutil"
testutils "pkg.berachain.dev/polaris/cosmos/testing/utils"
"pkg.berachain.dev/polaris/cosmos/x/evm/plugins/precompile/log"
evmtypes "pkg.berachain.dev/polaris/cosmos/x/evm/types"
Expand Down Expand Up @@ -481,7 +480,7 @@ var _ = Describe("Bank Precompile Test", func() {
_, err = contract.Send(
pCtx,
common.BytesToAddress(toAcc),
testutil.SdkCoinsToEvmCoins(sortedSdkCoins),
sdkCoinsToEvmCoins(sortedSdkCoins),
)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -513,7 +512,7 @@ var _ = Describe("Bank Precompile Test", func() {
_, err = contract.Send(
ctx,
common.BytesToAddress(toAcc),
testutil.SdkCoinsToEvmCoins(coinsToSend),
sdkCoinsToEvmCoins(coinsToSend),
)
Expect(err).To(MatchError(precompile.ErrInvalidCoin))
})
Expand Down Expand Up @@ -556,3 +555,23 @@ func getTestMetadata() []banktypes.Metadata {
},
}
}

func sdkCoinsToEvmCoins(sdkCoins sdk.Coins) []struct {
Amount *big.Int `json:"amount"`
Denom string `json:"denom"`
} {
evmCoins := make([]struct {
Amount *big.Int `json:"amount"`
Denom string `json:"denom"`
}, len(sdkCoins))
for i, coin := range sdkCoins {
evmCoins[i] = struct {
Amount *big.Int `json:"amount"`
Denom string `json:"denom"`
}{
Amount: coin.Amount.BigInt(),
Denom: coin.Denom,
}
}
return evmCoins
}
5 changes: 2 additions & 3 deletions cosmos/precompile/governance/governance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (

cbindings "pkg.berachain.dev/polaris/contracts/bindings/cosmos/lib"
generated "pkg.berachain.dev/polaris/contracts/bindings/cosmos/precompile/governance"
"pkg.berachain.dev/polaris/cosmos/precompile/testutil"
testutils "pkg.berachain.dev/polaris/cosmos/testing/utils"
"pkg.berachain.dev/polaris/cosmos/types"
"pkg.berachain.dev/polaris/eth/common"
Expand Down Expand Up @@ -72,11 +71,11 @@ var _ = Describe("Governance Precompile", func() {
)

BeforeEach(func() {
t := testutil.GinkgoTestReporter{}
t := ginkgoTestReporter{}
mockCtrl = gomock.NewController(t)
types.SetupCosmosConfig()
caller = testutils.Alice.Bytes()
sdkCtx, ak, bk, gk = testutil.Setup(mockCtrl, caller)
sdkCtx, ak, bk, gk = setupGovTest(mockCtrl, caller)
contract = utils.MustGetAs[*Contract](NewPrecompileContract(
ak,
governancekeeper.NewMsgServerImpl(gk),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package testutil
package governance

import (
"fmt"
Expand Down Expand Up @@ -51,18 +51,19 @@ import (
)

// Test Reporter to use governance module tests with Ginkgo.
type GinkgoTestReporter struct{}
type ginkgoTestReporter struct{}

func (g GinkgoTestReporter) Errorf(format string, args ...interface{}) {
func (g ginkgoTestReporter) Errorf(format string, args ...interface{}) {
Fail(fmt.Sprintf(format, args...))
}

func (g GinkgoTestReporter) Fatalf(format string, args ...interface{}) {
func (g ginkgoTestReporter) Fatalf(format string, args ...interface{}) {
Fail(fmt.Sprintf(format, args...))
}

// Helper functions for setting up the tests.
func Setup(ctrl *gomock.Controller, caller sdk.AccAddress) (
// TODO: deprecate this garbage.
func setupGovTest(ctrl *gomock.Controller, caller sdk.AccAddress) (
sdk.Context, authkeeper.AccountKeeperI, bankkeeper.Keeper, *governancekeeper.Keeper,
) {
// Setup the keepers and context.
Expand Down
9 changes: 4 additions & 5 deletions cosmos/x/evm/keeper/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"

"pkg.berachain.dev/polaris/cosmos/x/evm/plugins"
"pkg.berachain.dev/polaris/cosmos/x/evm/plugins/block"
"pkg.berachain.dev/polaris/cosmos/x/evm/plugins/configuration"
"pkg.berachain.dev/polaris/cosmos/x/evm/plugins/engine"
Expand All @@ -49,7 +48,7 @@ var _ core.PolarisHostChain = (*host)(nil)
// It includes core.PolarisHostChain and functions that are called in other packages.
type Host interface {
core.PolarisHostChain
GetAllPlugins() []plugins.Base
GetAllPlugins() []any
Setup(
storetypes.StoreKey,
storetypes.StoreKey,
Expand Down Expand Up @@ -103,7 +102,7 @@ func (h *host) Setup(
) {
// Setup the state, precompile, historical, and txpool plugins
h.sp = state.NewPlugin(ak, storeKey, log.NewFactory(h.pcs().GetPrecompiles()))
h.pp = precompile.NewPlugin(h.pcs().GetPrecompiles(), h.sp)
h.pp = precompile.NewPlugin(h.pcs().GetPrecompiles())
// TODO: re-enable historical plugin using ABCI listener.
h.hp = historical.NewPlugin(h.cp, h.bp, nil, storeKey)
h.txp.SetNonceRetriever(h.sp)
Expand Down Expand Up @@ -153,6 +152,6 @@ func (h *host) GetTxPoolPlugin() core.TxPoolPlugin {
}

// GetAllPlugins returns all the plugins.
func (h *host) GetAllPlugins() []plugins.Base {
return []plugins.Base{h.bp, h.cp, h.gp, h.hp, h.pp, h.sp, h.txp}
func (h *host) GetAllPlugins() []any {
return []any{h.bp, h.cp, h.gp, h.hp, h.pp, h.sp, h.txp}
}
4 changes: 0 additions & 4 deletions cosmos/x/evm/plugins/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import (
"pkg.berachain.dev/polaris/eth/core"
)

// Base is the base interface which all x/evm Polaris plugins must implement

type Base interface{}

// HasGenesis represents the base class that all x/evm Polaris plugins which have
// InitGenesis or ExportGenesis methods must implement

Expand Down
1 change: 0 additions & 1 deletion cosmos/x/evm/plugins/block/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
)

type Plugin interface {
plugins.Base
plugins.HasGenesis
core.BlockPlugin

Expand Down
10 changes: 0 additions & 10 deletions cosmos/x/evm/plugins/configuration/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ import (
storetypes "cosmossdk.io/store/types"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"pkg.berachain.dev/polaris/cosmos/x/evm/plugins"
"pkg.berachain.dev/polaris/eth/common"
"pkg.berachain.dev/polaris/eth/core"
"pkg.berachain.dev/polaris/eth/params"
)

// Plugin is the interface that must be implemented by the plugin.
type Plugin interface {
plugins.Base
plugins.HasGenesis
core.ConfigurationPlugin
SetChainConfig(*params.ChainConfig)
Expand All @@ -60,10 +57,3 @@ func (p *plugin) Prepare(ctx context.Context) {
sCtx := sdk.UnwrapSDKContext(ctx)
p.paramsStore = sCtx.KVStore(p.storeKey)
}

// FeeCollector implements the core.ConfigurationPlugin interface.
func (p *plugin) FeeCollector() *common.Address {
// TODO: parameterize fee collector name.
addr := common.BytesToAddress([]byte(authtypes.FeeCollectorName))
return &addr
}
25 changes: 0 additions & 25 deletions cosmos/x/evm/plugins/configuration/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,9 @@ var _ = Describe("Plugin", func() {
Describe("Prepare", func() {
It("should initialize the params store", func() {
p.Prepare(ctx)

// Check that the params store is initialized.
expect := ctx.KVStore(p.storeKey)
Expect(p.paramsStore).To(Equal(expect))
})
})

Describe("ChainConfig", func() {
Context("when the params store is empty", func() {
It("should return nil", func() {
config := p.ChainConfig()
Expect(config).To(BeNil())
})
})

Context("when the params store contains valid params", func() {
// It("should return the chain config", func() {
// storedParams := types.Params{
// EvmDenom: "eth",
// ExtraEIPs: []int64{123},
// }
// bz, err := storedParams.Marshal()
// Expect(err).ToNot(HaveOccurred())
// p.paramsStore.Set([]byte{types.ParamsKey}, bz)

// config := p.ChainConfig()
// Expect(config).To(Equal(params.DefaultChainConfig))
// })
})
})
})
72 changes: 54 additions & 18 deletions cosmos/x/evm/plugins/configuration/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,57 @@

package configuration

// . "github.com/onsi/ginkgo/v2"
// . "github.com/onsi/gomega"

// var _ = Describe("Plugin", func() {
// var (
// // p *plugin
// // ctx sdk.Context
// )

// BeforeEach(func() {
// // ctx = testutil.NewContext()
// // storeKey := storetypes.NewKVStoreKey("evm")
// // // p = &plugin{
// // storeKey: storeKey,
// // paramsStore: ctx.KVStore(storeKey),
// // }
// })
// })
import (
storetypes "cosmossdk.io/store/types"

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

testutil "pkg.berachain.dev/polaris/cosmos/testing/utils"
"pkg.berachain.dev/polaris/eth/params"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Plugin", func() {
var (
p *plugin
ctx sdk.Context
)

BeforeEach(func() {
ctx = testutil.NewContext()
storeKey := storetypes.NewKVStoreKey("evm")
p = &plugin{
storeKey: storeKey,
paramsStore: ctx.KVStore(storeKey),
}
})

Describe("Prepare", func() {
It("should initialize the params store", func() {
p.Prepare(ctx)

// Check that the params store is initialized.
expect := ctx.KVStore(p.storeKey)
Expect(p.paramsStore).To(Equal(expect))
})
})

Describe("ChainConfig", func() {
Context("when the params store is empty", func() {
It("should return nil", func() {
config := p.ChainConfig()
Expect(config).To(BeNil())
})
})

Context("when the params store contains valid params", func() {
It("should return the chain config", func() {
p.SetChainConfig(params.DefaultChainConfig)
config := p.ChainConfig()
Expect(config).To(Equal(params.DefaultChainConfig))
})
})
})
})
2 changes: 0 additions & 2 deletions cosmos/x/evm/plugins/engine/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package engine
import (
"github.com/cosmos/cosmos-sdk/client"

"pkg.berachain.dev/polaris/cosmos/x/evm/plugins"
"pkg.berachain.dev/polaris/eth/core"
)

Expand All @@ -32,7 +31,6 @@ var _ Plugin = (*plugin)(nil)

// Plugin defines the required functions of the transaction pool plugin.
type Plugin interface {
plugins.Base
core.EnginePlugin
Start(client.Context)
}
Expand Down
2 changes: 0 additions & 2 deletions cosmos/x/evm/plugins/gas/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

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

"pkg.berachain.dev/polaris/cosmos/x/evm/plugins"
"pkg.berachain.dev/polaris/eth/core"
"pkg.berachain.dev/polaris/eth/core/vm"
)
Expand All @@ -38,7 +37,6 @@ const gasMeterDescriptor = `polaris-gas-plugin`

// Plugin is the interface that must be implemented by the plugin.
type Plugin interface {
plugins.Base
core.GasPlugin
}

Expand Down
Loading

0 comments on commit e8966a8

Please sign in to comment.