Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update x/stakingplus to use Finschia/cosmos-sdk #1225

Merged
merged 31 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/pr_labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
# - docs/architecture/**/*
"C:x/foundation":
- x/foundation/**/*

"C:x/stakingplus":
- x/stakingplus/**/*
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,34 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: x/foundation/

test-x-stakingplus:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "1.21"
check-latest: true
cache: true
cache-dependency-path: x/stakingplus/go.sum
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
x/stakingplus/**/*.go
x/stakingplus/go.mod
x/stakingplus/go.sum
- name: tests
if: env.GIT_DIFF
run: |
cd x/stakingplus
go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./...
- name: sonarcloud
if: ${{ env.GIT_DIFF && !github.event.pull_request.draft && env.SONAR_TOKEN != null }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: x/stakingplus/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased](https://github.com/Finschia/finschia-sdk/compare/v0.48.0...HEAD)

### Features
* (x/staking) [\#1214](https://github.com/Finschia/finschia-sdk/pull/1214) update x/stakingplus to use Finschia/cosmos-sdk
* (x/foundation) [\#1198](https://github.com/Finschia/finschia-sdk/pull/1198) update x/foundation to use Finschia/cosmos-sdk
* (all) [\#1205](https://github.com/Finschia/finschia-sdk/pull/1205) delegate native logics to Finschia/cosmos-sdk
* (consensus) [\#1178](https://github.com/Finschia/finschia-sdk/pull/1178) change the consensus from Ostracon to Tendermint v0.34.24
Expand Down
1 change: 1 addition & 0 deletions go.work.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ use (
./simapp
./tests
./x/foundation
./x/stakingplus
)
1 change: 1 addition & 0 deletions scripts/mockgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

mockgen_cmd="mockgen"
$mockgen_cmd -source=x/foundation/expected_keepers.go -package testutil -destination x/foundation/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/stakingplus/expected_keepers.go -package testutil -destination x/stakingplus/testutil/expected_keepers_mocks.go
4 changes: 2 additions & 2 deletions scripts/protocgen-pulsar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ echo "Cleaning API directory"
echo "Generating API module"
(cd proto; buf generate --template buf.gen.pulsar.yaml)

echo "Generate Pulsar Test Data"
(cd testutil/testdata; buf generate --template buf.gen.pulsar.yaml)
# echo "Generate Pulsar Test Data"
# (cd testutil/testdata; buf generate --template buf.gen.pulsar.yaml)
4 changes: 2 additions & 2 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
_ "github.com/cosmos/cosmos-sdk/x/slashing" // import for side-effects
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
_ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

foundationmodulev1 "github.com/Finschia/finschia-sdk/api/lbm/foundation/module/v1"
foundation "github.com/Finschia/finschia-sdk/x/foundation"
_ "github.com/Finschia/finschia-sdk/x/foundation/module" // import for side-effects
_ "github.com/Finschia/finschia-sdk/x/foundation/module" // import for side-effects
_ "github.com/Finschia/finschia-sdk/x/stakingplus/module" // import for side-effects
)

var (
Expand Down
6 changes: 3 additions & 3 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"

foundationmodule "github.com/Finschia/finschia-sdk/x/foundation/module"
stakingplusmodule "github.com/Finschia/finschia-sdk/x/stakingplus/module"
)

func TestSimAppExportAndBlockedAddrs(t *testing.T) {
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestRunMigrations(t *testing.T) {
"bank": 1,
"auth": auth.AppModule{}.ConsensusVersion(),
"authz": authzmodule.AppModule{}.ConsensusVersion(),
"staking": staking.AppModule{}.ConsensusVersion(),
"staking": stakingplusmodule.AppModule{}.ConsensusVersion(),
"mint": mint.AppModule{}.ConsensusVersion(),
"distribution": distribution.AppModule{}.ConsensusVersion(),
"slashing": slashing.AppModule{}.ConsensusVersion(),
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
"bank": bank.AppModule{}.ConsensusVersion(),
"auth": auth.AppModule{}.ConsensusVersion(),
"authz": authzmodule.AppModule{}.ConsensusVersion(),
"staking": staking.AppModule{}.ConsensusVersion(),
"staking": stakingplusmodule.AppModule{}.ConsensusVersion(),
"mint": mint.AppModule{}.ConsensusVersion(),
"distribution": distribution.AppModule{}.ConsensusVersion(),
"slashing": slashing.AppModule{}.ConsensusVersion(),
Expand Down
2 changes: 2 additions & 0 deletions simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
cosmossdk.io/x/upgrade v0.1.1
github.com/Finschia/finschia-sdk/api v0.0.0-20231227090232-78fde403b78c
github.com/Finschia/finschia-sdk/x/foundation v0.0.0-00010101000000-000000000000
github.com/Finschia/finschia-sdk/x/stakingplus v0.0.0-00010101000000-000000000000
github.com/cometbft/cometbft v0.38.2
github.com/cosmos/cosmos-db v1.0.0
// this version is not used as it is always replaced by the latest Cosmos SDK version
Expand Down Expand Up @@ -206,6 +207,7 @@ replace (
// Simapp always use the latest version of the finschia-sdk
github.com/Finschia/finschia-sdk/api => ../api
github.com/Finschia/finschia-sdk/x/foundation => ../x/foundation
github.com/Finschia/finschia-sdk/x/stakingplus => ../x/stakingplus
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1
Expand Down
30 changes: 30 additions & 0 deletions tests/e2e/stakingplus/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build e2e
// +build e2e

package stakingplus

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/go-bip39"

"github.com/Finschia/finschia-sdk/simapp"
)

func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)

cfg.NumValidators = 1

entropySeed, err := bip39.NewEntropy(256)
require.NoError(t, err)
mnemonic, err := bip39.NewMnemonic(entropySeed)
require.NoError(t, err)
cfg.Mnemonics = []string{mnemonic}

suite.Run(t, NewE2ETestSuite(cfg))
}
16 changes: 16 additions & 0 deletions tests/e2e/stakingplus/grantee.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"pubkey": {
"@type": "/cosmos.crypto.ed25519.PubKey",
"key": "l3eo4WwjQBtK1TrxPSXPs8mNUofgZm3XX+G2UOSWqq4="
},
"amount": "100stake",
"moniker": "grantee",
"identity": "optional identity signature (ex. UPort or Keybase)",
"website": "validator's (optional) website",
"security": "validator's (optional) security contact email",
"details": "validator's (optional) details",
"commission-rate": "0.1",
"commission-max-rate": "0.2",
"commission-max-change-rate": "0.01",
"min-self-delegation": "1"
}
16 changes: 16 additions & 0 deletions tests/e2e/stakingplus/stranger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"pubkey": {
"@type": "/cosmos.crypto.ed25519.PubKey",
"key": "4wf9IfLAIjtTFNEsBWLmzGFAhtw5w4FKsPJn4Dk2XPg="
},
"amount": "100stake",
"moniker": "stranger",
"identity": "optional identity signature (ex. UPort or Keybase)",
"website": "validator's (optional) website",
"security": "validator's (optional) security contact email",
"details": "validator's (optional) details",
"commission-rate": "0.1",
"commission-max-rate": "0.2",
"commission-max-change-rate": "0.01",
"min-self-delegation": "1"
}
181 changes: 181 additions & 0 deletions tests/e2e/stakingplus/suite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package stakingplus

import (
"fmt"
"time"

"github.com/stretchr/testify/suite"

"cosmossdk.io/core/address"
"cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/client/flags"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/Finschia/finschia-sdk/x/foundation"
"github.com/Finschia/finschia-sdk/x/stakingplus"
)

type E2ETestSuite struct {
suite.Suite

cfg network.Config
network *network.Network

grantee sdk.AccAddress
permanentMember sdk.AccAddress
stranger sdk.AccAddress

addressCodec address.Codec
valAddressCodec address.Codec
}

func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
return &E2ETestSuite{cfg: cfg}
}

func (s *E2ETestSuite) SetupSuite() {
s.T().Log("setting up e2e test suite")

s.addressCodec = addresscodec.NewBech32Codec("link")
s.valAddressCodec = addresscodec.NewBech32Codec("linkvaloper")

genesisState := s.cfg.GenesisState

var foundationData foundation.GenesisState
s.Require().NoError(s.cfg.Codec.UnmarshalJSON(genesisState[foundation.ModuleName], &foundationData))

// enable foundation tax
params := foundation.Params{
FoundationTax: math.LegacyMustNewDecFromStr("0.2"),
}
foundationData.Params = params

var strangerMnemonic string
var granteeMnemonic string
var permanentMemberMnemonic string
granteeMnemonic, s.grantee = s.createMnemonic("grantee")
strangerMnemonic, s.stranger = s.createMnemonic("stranger")
permanentMemberMnemonic, s.permanentMember = s.createMnemonic("permanentmember")

foundationData.Members = []foundation.Member{
{
Address: s.bytesToString(s.permanentMember),
Metadata: "permanent member",
},
}

info := foundation.DefaultFoundation()
info.TotalWeight = math.LegacyNewDecFromInt(math.NewInt(int64(len(foundationData.Members))))
err := info.SetDecisionPolicy(&foundation.ThresholdDecisionPolicy{
Threshold: math.LegacyOneDec(),
Windows: &foundation.DecisionPolicyWindows{
VotingPeriod: 7 * 24 * time.Hour,
},
})
s.Require().NoError(err)
foundationData.Foundation = info

// enable censorship
censorships := []foundation.Censorship{
{
MsgTypeUrl: sdk.MsgTypeURL((*stakingtypes.MsgCreateValidator)(nil)),
Authority: foundation.CensorshipAuthorityFoundation,
},
}
foundationData.Censorships = censorships

val1 := getValidator(s.T(), s.T().TempDir(), s.cfg, 0)
for _, grantee := range []sdk.AccAddress{s.grantee, val1} {
ga := foundation.GrantAuthorization{
Grantee: s.bytesToString(grantee),
}.WithAuthorization(&stakingplus.CreateValidatorAuthorization{
ValidatorAddress: s.bytesToValString(grantee),
})
s.Require().NotNil(ga)
foundationData.Authorizations = append(foundationData.Authorizations, *ga)
}

foundationDataBz, err := s.cfg.Codec.MarshalJSON(&foundationData)
s.Require().NoError(err)
genesisState[foundation.ModuleName] = foundationDataBz
s.cfg.GenesisState = genesisState

s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)

_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)

s.createAccount("grantee", granteeMnemonic)
s.createAccount("stranger", strangerMnemonic)
s.createAccount("permanentmember", permanentMemberMnemonic)
}

func (s *E2ETestSuite) TearDownSuite() {
s.T().Log("tearing down e2e test suite")
s.network.Cleanup()
}

func (s *E2ETestSuite) bytesToString(addr sdk.AccAddress) string {
str, err := s.addressCodec.BytesToString(addr)
s.Require().NoError(err)
return str
}

func (s *E2ETestSuite) bytesToValString(addr sdk.AccAddress) string {
str, err := s.valAddressCodec.BytesToString(addr)
s.Require().NoError(err)
return str
}

// creates an account
func (s *E2ETestSuite) createMnemonic(uid string) (string, sdk.AccAddress) {
cstore := keyring.NewInMemory(s.cfg.Codec)
info, mnemonic, err := cstore.NewMnemonic(uid, keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
s.Require().NoError(err)

addr, err := info.GetAddress()
s.Require().NoError(err)

return mnemonic, addr
}

// creates an account and send some coins to it for the future transactions.
func (s *E2ETestSuite) createAccount(uid, mnemonic string) {
commonArgs := []string{
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100)))),
}

val := s.network.Validators[0]
info, err := val.ClientCtx.Keyring.NewAccount(uid, mnemonic, keyring.DefaultBIP39Passphrase, sdk.FullFundraiserPath, hd.Secp256k1)
s.Require().NoError(err)

addr, err := info.GetAddress()
s.Require().NoError(err)

fee := sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(1000)))
args := append([]string{
s.bytesToString(val.Address),
s.bytesToString(addr),
fee.String(),
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.bytesToString(val.Address)),
}, commonArgs...)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bankcli.NewSendTxCmd(s.addressCodec), args)
s.Require().NoError(err)

var res sdk.TxResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String())
s.Require().Zero(res.Code, out.String())

s.Require().NoError(s.network.WaitForNextBlock())
0Tech marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading