Skip to content

Commit

Permalink
Merge branch 'main' into rapha/add-docker-build
Browse files Browse the repository at this point in the history
  • Loading branch information
mbreithecker committed Oct 19, 2023
2 parents c80f84b + 934eb5d commit f480353
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# https://help.github.com/articles/about-codeowners

* @johnletey @mbreithecker @troykessler
* @mbreithecker @troykessler @shifty11
9 changes: 9 additions & 0 deletions .github/workflows/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: run all jobs
on: push

jobs:
lint:
uses: ./.github/workflows/lint.yml

test:
uses: ./.github/workflows/test.yml
44 changes: 27 additions & 17 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
on: push
name: lint
on:
workflow_call:

jobs:
buf:
runs-on: ubuntu-latest
steps:
# Run `git checkout`
- uses: actions/checkout@v3
# Checkout the repository
- name: Checkout the repository
uses: actions/checkout@v4
# Install `buf`
- uses: bufbuild/buf-setup-action@v1
- name: Install `buf`
uses: bufbuild/buf-setup-action@v1
with:
github_token: ${{ github.token }}
# Lint Protobuf files
- uses: bufbuild/buf-lint-action@v1
- name: Lint Protobuf files
uses: bufbuild/buf-lint-action@v1
with:
buf_token: ${{ secrets.BUF_TOKEN }}

# TODO(@john): Figure out why linting passes locally but not here.
# golangci:
# runs-on: ubuntu-latest
# steps:
# # Run `git checkout`
# - uses: actions/checkout@v3
# # Install `go`
# - uses: actions/setup-go@v3
# # Lint Go files
# - uses: golangci/golangci-lint-action@v3
# with:
# args: --timeout=10m
golangci:
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout the repository
uses: actions/checkout@v4
# Setup Golang
- name: 🐿 Setup Golang
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
# Lint go files with golangci-lint
- name: Lint go files with golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=10m
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: test
on:
workflow_call:

jobs:
test:
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Check out repository code
uses: actions/checkout@v4
# Setup Golang
- name: 🐿 Setup Golang
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
# Test & coverage report creation
- name: Test & coverage report creation
run: go test -cover -mod=readonly ./x/...
7 changes: 0 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ endif
### Development ###
###############################################################################

# TODO(@john): Switch to the Docker image?
dev:
@ignite chain serve --reset-once --skip-proto --verbose

Expand All @@ -144,12 +143,6 @@ lint:
@go run $(golangci_lint_cmd) run --skip-dirs scripts --timeout=10m
@echo "✅ Completed linting!"

# TODO(@john): Can we remove this since we use GolangCI?
vet:
@echo "🤖 Running vet..."
@go vet ./...
@echo "✅ Completed vet!"

###############################################################################
### Protobuf ###
###############################################################################
Expand Down
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import (
group "github.com/cosmos/cosmos-sdk/x/group/module"
// IBC Core
ibc "github.com/cosmos/ibc-go/v7/modules/core"
ibcClientHandler "github.com/cosmos/ibc-go/v7/modules/core/02-client" // TODO
ibcClientHandler "github.com/cosmos/ibc-go/v7/modules/core/02-client"
ibcClientTypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcPortTypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
ibcExported "github.com/cosmos/ibc-go/v7/modules/core/exported"
Expand Down Expand Up @@ -345,7 +345,7 @@ func NewKYVEApp(
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icaControllerTypes.SubModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icaHostTypes.SubModuleName)

// TODO(@john): Seal x/capability keeper.
app.CapabilityKeeper.Seal()

// add keepers
app.AccountKeeper = authKeeper.NewAccountKeeper(
Expand Down Expand Up @@ -384,7 +384,7 @@ func NewKYVEApp(
appCodec,
keys[mintTypes.StoreKey],
app.StakingKeeper,
&app.StakersKeeper, // TODO(@john)
&app.StakersKeeper, // This is a pointer because the stakers keeper is not initialized yet.
app.AccountKeeper,
app.BankKeeper,
authTypes.FeeCollectorName,
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades/v1_4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
upgradeTypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

//nolint:all
//goland:noinspection GoDeprecation
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
Expand Down
2 changes: 1 addition & 1 deletion cmd/kyved/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewRootCmd(encodingConfig kyveApp.EncodingConfig) *cobra.Command {
tmCli.NewCompletionCmd(rootCmd, true),
debug.Cmd(),
config.Cmd(),
pruning.PruningCmd(ac.createApp),
pruning.Cmd(ac.createApp, kyveApp.DefaultNodeHome),

rpc.StatusCommand(),
queryCommand(),
Expand Down
20 changes: 13 additions & 7 deletions testutil/integration/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/KYVENetwork/chain/x/delegation"
delegationtypes "github.com/KYVENetwork/chain/x/delegation/types"
globalTypes "github.com/KYVENetwork/chain/x/global/types"
"github.com/KYVENetwork/chain/x/pool"
poolmodule "github.com/KYVENetwork/chain/x/pool"
querytypes "github.com/KYVENetwork/chain/x/query/types"
"github.com/KYVENetwork/chain/x/stakers"
stakertypes "github.com/KYVENetwork/chain/x/stakers/types"
Expand All @@ -24,10 +24,7 @@ func (suite *KeeperTestSuite) PerformValidityChecks() {
// verify pool module
suite.VerifyPoolModuleAssetsIntegrity()
suite.VerifyPoolTotalFunds()

// TODO(@troy,@max): Figure out a better way to check this when disabling pools.
// suite.VerifyPoolQueries()

suite.VerifyPoolQueries()
suite.VerifyPoolGenesisImportExport()

// verify stakers module
Expand Down Expand Up @@ -98,6 +95,15 @@ func (suite *KeeperTestSuite) VerifyPoolQueries() {
poolsQuery = append(poolsQuery, activePoolsQuery.Pools...)
poolsQuery = append(poolsQuery, disabledPoolsQuery.Pools...)

// sort pools by id
for i := range poolsQuery {
for j := range poolsQuery {
if poolsQuery[i].Id < poolsQuery[j].Id {
poolsQuery[i], poolsQuery[j] = poolsQuery[j], poolsQuery[i]
}
}
}

Expect(activePoolsQueryErr).To(BeNil())
Expect(disabledPoolsQueryErr).To(BeNil())

Expand Down Expand Up @@ -155,15 +161,15 @@ func (suite *KeeperTestSuite) VerifyPoolQueries() {
}

func (suite *KeeperTestSuite) VerifyPoolGenesisImportExport() {
genState := pool.ExportGenesis(suite.Ctx(), suite.App().PoolKeeper)
genState := poolmodule.ExportGenesis(suite.Ctx(), suite.App().PoolKeeper)

// Delete all entries in Pool Store
store := suite.Ctx().KVStore(suite.App().PoolKeeper.StoreKey())
suite.deleteStore(store)

err := genState.Validate()
Expect(err).To(BeNil())
pool.InitGenesis(suite.Ctx(), suite.App().PoolKeeper, *genState)
poolmodule.InitGenesis(suite.Ctx(), suite.App().PoolKeeper, *genState)
}

// =====================
Expand Down
22 changes: 19 additions & 3 deletions x/delegation/keeper/msg_server_delegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST CASES - msg_server_delegate.go
* Payout delegators
* Don't pay out rewards twice
* Delegate to validator with 0 $KYVE
* TODO(@max): Delegate to multiple validators
* Delegate to multiple validators
*/

Expand Down Expand Up @@ -276,6 +276,16 @@ var _ = Describe("msg_server_delegate.go", Ordered, func() {
})

// ACT
s.RunTxDelegatorSuccess(&types.MsgDelegate{
Creator: i.DUMMY[1],
Staker: i.ALICE,
Amount: 200 * i.KYVE,
})
s.RunTxDelegatorSuccess(&types.MsgDelegate{
Creator: i.DUMMY[1],
Staker: i.BOB,
Amount: 200 * i.KYVE,
})
s.RunTxDelegatorSuccess(&types.MsgDelegate{
Creator: i.DUMMY[1],
Staker: i.CHARLIE,
Expand All @@ -286,8 +296,14 @@ var _ = Describe("msg_server_delegate.go", Ordered, func() {
s.PerformValidityChecks()

poolModuleBalance := s.GetBalanceFromModule(types.ModuleName)
Expect(poolModuleBalance).To(Equal(200*i.KYVE + aliceSelfDelegation + bobSelfDelegation))
Expect(s.GetBalanceFromAddress(i.DUMMY[1])).To(Equal(800 * i.KYVE))
Expect(poolModuleBalance).To(Equal(600*i.KYVE + aliceSelfDelegation + bobSelfDelegation))
Expect(s.GetBalanceFromAddress(i.DUMMY[1])).To(Equal(400 * i.KYVE))

aliceDelegation := s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.ALICE)
Expect(aliceDelegation).To(Equal(200*i.KYVE + aliceSelfDelegation))

bobDelegation := s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.BOB)
Expect(bobDelegation).To(Equal(200*i.KYVE + bobSelfDelegation))

charlieDelegation := s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.CHARLIE)
Expect(charlieDelegation).To(Equal(200 * i.KYVE))
Expand Down
8 changes: 5 additions & 3 deletions x/delegation/keeper/msg_server_undelegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ TEST CASES - msg_server_undelegate.go
* JoinA, Slash, JoinB, PayoutReward
* Slash twice
* Start unbonding, slash twice, payout, await undelegation
TODO(@max): joinA slash joinB slash -> remaining delegation
*/

var _ = Describe("msg_server_undelegate.go", Ordered, func() {
Expand Down Expand Up @@ -493,6 +490,11 @@ var _ = Describe("msg_server_undelegate.go", Ordered, func() {
// ASSERT
Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(666_666_666)))
Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1])).To(Equal(uint64(2_666_666_666)))

// must be the same as before
Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.ALICE)).To(Equal((50 + 25) * i.KYVE))
Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(5 * i.KYVE))
Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.ALICE, i.DUMMY[1])).To(Equal(20 * i.KYVE))
})

It("Slash twice", func() {
Expand Down
64 changes: 60 additions & 4 deletions x/delegation/keeper/msg_server_withdraw_rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
pooltypes "github.com/KYVENetwork/chain/x/pool/types"
stakerstypes "github.com/KYVENetwork/chain/x/stakers/types"
sdk "github.com/cosmos/cosmos-sdk/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand All @@ -17,10 +18,8 @@ TEST CASES - msg_server_withdraw_rewards.go
* Payout rewards which cause rounding issues and withdraw
* Withdraw from a non-existing delegator
* Test invalid payouts to delegators
* TODO(@max): Test withdrawal of rewards which are zero
* TODO(@max): Test withdrawal of rewards with multiple slashes
* Withdraw rewards which are zero
* Withdraw rewards with multiple slashes
*/

var _ = Describe("msg_server_withdraw_rewards.go", Ordered, func() {
Expand Down Expand Up @@ -171,4 +170,61 @@ var _ = Describe("msg_server_withdraw_rewards.go", Ordered, func() {
Expect(err1).To(HaveOccurred())
Expect(err2).To(HaveOccurred())
})

It("Withdraw rewards which are zero", func() {
// ARRANGE
s.RunTxDelegatorSuccess(&types.MsgDelegate{
Creator: i.DUMMY[0],
Staker: i.ALICE,
Amount: 1,
})
startBalance := s.GetBalanceFromAddress(i.DUMMY[0])

// ACT
Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(0)))

s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{
Creator: i.DUMMY[0],
Staker: i.ALICE,
})

// ASSERT
Expect(s.GetBalanceFromAddress(i.DUMMY[0])).To(Equal(startBalance))
Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(0)))
})

It("Withdraw rewards with multiple slashes", func() {
// ARRANGE
s.RunTxDelegatorSuccess(&types.MsgDelegate{
Creator: i.DUMMY[0],
Staker: i.ALICE,
Amount: 10 * i.KYVE,
})
startBalance := s.GetBalanceFromAddress(i.DUMMY[0])

// ACT
params := s.App().DelegationKeeper.GetParams(s.Ctx())
params.UploadSlash = sdk.MustNewDecFromStr("0.5")
s.App().DelegationKeeper.SetParams(s.Ctx(), params)

// Slash 50%
s.App().DelegationKeeper.SlashDelegators(s.Ctx(), 0, i.ALICE, types.SLASH_TYPE_UPLOAD)
PayoutRewards(s, i.ALICE, 5*i.KYVE)

// Slash 50% again
s.App().DelegationKeeper.SlashDelegators(s.Ctx(), 0, i.ALICE, types.SLASH_TYPE_UPLOAD)
PayoutRewards(s, i.ALICE, 5*i.KYVE)

s.PerformValidityChecks()

// ASSERT
Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(10 * i.KYVE))

s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{
Creator: i.DUMMY[0],
Staker: i.ALICE,
})
Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(0)))
Expect(s.GetBalanceFromAddress(i.DUMMY[0])).To(Equal(startBalance + 10*i.KYVE))
})
})
4 changes: 2 additions & 2 deletions x/team/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type VestingStatus struct {
var (
TEAM_FOUNDATION_STRING = "kyve1u7ukf2nv6v5j5y2yqprm8yqruue2rlmrkx4xgq"
TEAM_BCP_STRING = "kyve1ruxaec07ca3dh0amkzxjap7av3xjt5vjgnd424"
TEAM_ALLOCATION_STRING = "165000000000000"
TGE_STRING = "2023-03-14T14:03:14"
TEAM_ALLOCATION_STRING = "165000000000000000"
TGE_STRING = "2023-02-01T10:34:15"
)

// Convert passed build variables (string) to the corresponding int values
Expand Down

0 comments on commit f480353

Please sign in to comment.