Skip to content

Commit

Permalink
Merge branch 'main' into fix-allowed-msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Xingchen Liao authored Jun 13, 2023
2 parents 0abb096 + 3046382 commit ffebe54
Show file tree
Hide file tree
Showing 9 changed files with 435 additions and 69 deletions.
59 changes: 0 additions & 59 deletions .codecov.yml

This file was deleted.

55 changes: 48 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:

permissions:
contents: read
pull-requests: write

concurrency:
group: ci-${{ github.ref }}-tests
Expand Down Expand Up @@ -77,6 +78,7 @@ jobs:
part: ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19
Expand All @@ -86,25 +88,64 @@ jobs:
**/**.go
go.mod
go.sum
- uses: actions/download-artifact@v3
with:
name: "${{ github.sha }}-${{ matrix.part }}"
- name: Get data from Go build cache
# if: env.GIT_DIFF
if: ${{ false }}
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/golangci-lint
~/.cache/go-build
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
- uses: actions/download-artifact@v3
with:
name: "${{ github.sha }}-${{ matrix.part }}"
if: env.GIT_DIFF

- name: test & coverage report creation
run: |
cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -race -timeout 5m -coverprofile=${{ matrix.part }}profile.out -covermode=atomic -tags='ledger test_ledger_mock'
if: env.GIT_DIFF
- uses: actions/upload-artifact@v3
with:
name: "${{ github.sha }}-${{ matrix.part }}-coverage"
path: ./${{ matrix.part }}profile.out

upload-coverage-report:
needs: tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19

# Download all coverage reports from the 'tests' job
- name: Download coverage reports
uses: actions/download-artifact@v3

- name: Set GOPATH
run: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV

- name: Add GOPATH/bin to PATH
run: echo "GOBIN=$(go env GOPATH)/bin" >> $GITHUB_ENV

- name: Install gocovmerge
run: go get github.com/wadey/gocovmerge && go install github.com/wadey/gocovmerge

- name: Merge coverage reports
run: gocovmerge $(find . -type f -name '*profile.out') > coverage.txt

- name: Check coverage report lines
run: wc -l coverage.txt
continue-on-error: true

- name: Check coverage report files
run: ls **/*profile.out
continue-on-error: true

# Now we upload the merged report to Codecov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.txt
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
25 changes: 25 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
coverage:
precision: 2
round: down
status:
# Learn more at https://docs.codecov.io/docs/commit-status
project:
default:
threshold: 1% # allow this much decrease on project
target: 70%

comment:
layout: "reach,diff,flags,tree,betaprofiling"
behavior: default # update if exists else create new
require_changes: true

ignore:
- "docs"
- "*.md"
- "*.rst"
- "**/*pb*.go"
- "tests/*"
- "tests/**/*"
- "x/**/test_common.go"
- "scripts/"
- "contrib"
4 changes: 1 addition & 3 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,7 @@ func (k BaseKeeper) DeferredSendCoinsFromAccountToModule(
}

func (k BaseKeeper) WriteDeferredOperations(ctx sdk.Context) []abci.Event {
return append(
k.WriteDeferredDepositsToModuleAccounts(ctx),
)
return k.WriteDeferredDepositsToModuleAccounts(ctx)
}

// WriteDeferredDepositsToModuleAccounts Iterates on all the lazy deposits and deposit them into the store
Expand Down
96 changes: 96 additions & 0 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,32 @@ func (suite *IntegrationTestSuite) TestSupply() {
require.Equal(total.String(), "")
}

func (suite *IntegrationTestSuite) TestIterateSupply() {
ctx := suite.ctx

require := suite.Require()

// add module accounts to supply keeper
authKeeper, keeper := suite.initKeepersWithmAccPerms(make(map[string]bool))

initialPower := int64(100)
initTokens := suite.app.StakingKeeper.TokensFromConsensusPower(ctx, initialPower)
totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens), newFooCoin(123), newBarCoin(240))

// set burnerAcc balance
authKeeper.SetModuleAccount(ctx, burnerAcc)
require.NoError(keeper.MintCoins(ctx, authtypes.Minter, totalSupply))
require.NoError(keeper.SendCoinsFromModuleToAccount(ctx, authtypes.Minter, burnerAcc.GetAddress(), totalSupply))

// test iterate supply
amounts := []sdk.Coin{}
keeper.IterateTotalSupply(ctx, func(c sdk.Coin) bool {
amounts = append(amounts, c)
return false
})
require.Equal(totalSupply, sdk.Coins(amounts))
}

func (suite *IntegrationTestSuite) TestSendCoinsFromModuleToAccount_Blocklist() {
ctx := suite.ctx

Expand Down Expand Up @@ -648,6 +674,45 @@ func (suite *IntegrationTestSuite) TestBurnCoinsWithDeferredBalance() {
suite.Require().Equal(newBarCoin(40), app.BankKeeper.GetSupply(ctx, "bar"))
}

func (suite *IntegrationTestSuite) TestWriteDeferredOperations() {
// add module accounts to supply keeper
ctx := suite.ctx
ctx = ctx.WithContextMemCache(sdk.NewContextMemCache())
authKeeper, keeper := suite.initKeepersWithmAccPerms(make(map[string]bool))
authKeeper.SetModuleAccount(ctx, multiPermAcc)
app := suite.app
app.BankKeeper = keeper

deferredBalances := sdk.NewCoins(newFooCoin(10), newBarCoin(50))

// set up balances this way to ensure that supply is incremented appropriately
addr2 := sdk.AccAddress([]byte("addr2_______________"))
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)
app.AccountKeeper.SetAccount(ctx, acc2)
suite.Require().NoError(simapp.FundAccount(app.BankKeeper, ctx, addr2, deferredBalances))
suite.Require().NoError(app.BankKeeper.DeferredSendCoinsFromAccountToModule(ctx, addr2, multiPerm, deferredBalances))

bankBalances := sdk.NewCoins(newFooCoin(20), newBarCoin(30))
// setup deferred balances
// ctx.ContextMemCache().UpsertDeferredSends(multiPerm, deferredBalances)
// set up bank balances
suite.Require().NoError(simapp.FundAccount(app.BankKeeper, ctx, multiPermAcc.GetAddress(), bankBalances))

// verify that bank balances are only the original bank balances
suite.Require().Equal(bankBalances, app.BankKeeper.GetAllBalances(ctx, multiPermAcc.GetAddress()))

// write deferred balances
app.BankKeeper.WriteDeferredOperations(ctx)

// verify total balance in module bank balances
suite.Require().Equal(sdk.NewCoins(newFooCoin(30), newBarCoin(80)), app.BankKeeper.GetAllBalances(ctx, multiPermAcc.GetAddress()))

// test error
ctx.ContextMemCache().GetDeferredSends().Set("asd", deferredBalances)
suite.Require().Panics(func() { app.BankKeeper.WriteDeferredOperations(ctx) })

}

func (suite *IntegrationTestSuite) TestValidateBalance() {
app, ctx := suite.app, suite.ctx
now := tmtime.Now()
Expand Down Expand Up @@ -1083,6 +1148,37 @@ func (suite *IntegrationTestSuite) TestDelegateCoins() {
suite.Require().Equal(delCoins, vestingAcc.GetDelegatedVesting())
}

func (suite *IntegrationTestSuite) TestDelegateCoinsFromAccountToModule() {
app, ctx := suite.app, suite.ctx
now := tmtime.Now()
ctx = ctx.WithBlockHeader(tmproto.Header{Time: now})

origCoins := sdk.NewCoins(sdk.NewInt64Coin("usei", 100))
delCoins := sdk.NewCoins(sdk.NewInt64Coin("usei", 50))
undelCoins := sdk.NewCoins(sdk.NewInt64Coin("usei", 20))

addr := sdk.AccAddress([]byte("addr2_______________"))
authKeeper, keeper := suite.initKeepersWithmAccPerms(make(map[string]bool))
authKeeper.SetModuleAccount(ctx, multiPermAcc)
app.BankKeeper = keeper

acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)

app.AccountKeeper.SetAccount(ctx, acc)
suite.Require().NoError(simapp.FundAccount(app.BankKeeper, ctx, addr, origCoins))

// test delegate from account to module
suite.Require().NoError(app.BankKeeper.DelegateCoinsFromAccountToModule(ctx, addr, multiPerm, delCoins))
// require the ability for a non-vesting account to delegate
suite.Require().Equal(origCoins.Sub(delCoins), app.BankKeeper.GetAllBalances(ctx, addr))
suite.Require().Equal(delCoins, app.BankKeeper.GetAllBalances(ctx, multiPermAcc.GetAddress()))

// test undelegate from module
suite.Require().NoError(app.BankKeeper.UndelegateCoinsFromModuleToAccount(ctx, multiPerm, addr, undelCoins))
suite.Require().Equal(origCoins.Sub(delCoins).Add(undelCoins...), app.BankKeeper.GetAllBalances(ctx, addr))
suite.Require().Equal(delCoins.Sub(undelCoins), app.BankKeeper.GetAllBalances(ctx, multiPermAcc.GetAddress()))
}

func (suite *IntegrationTestSuite) TestDelegateCoins_Invalid() {
app, ctx := suite.app, suite.ctx

Expand Down
Loading

0 comments on commit ffebe54

Please sign in to comment.