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

release: prepare release for v0.2.3 #394

Closed
wants to merge 9 commits into from
22 changes: 6 additions & 16 deletions .github/workflows/e2e-test.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: End to End Test
name: Tests / Code Coverage

on:
push:
Expand All @@ -9,7 +9,7 @@ on:
pull_request:

jobs:
end-to-end-test:
tests:
strategy:
matrix:
go-version: [1.20.x]
Expand Down Expand Up @@ -44,32 +44,22 @@ jobs:
${{ runner.os }}-go-
- name: Setup GitHub Token
run: git config --global url.https://$GH_ACCESS_TOKEN@github.com/.insteadOf https://github.com/
- name: Build
- name: run tests
run: |
make build
- name: start e2e local chain
run: |
make e2e_start_localchain
sleep 5
- name: run e2e test
run: |
make e2e_test
- name: stop e2e local chain
run: |
make e2e_stop_localchain
make test
- name: make coverage report
id: coverage-report
if: github.event_name == 'pull_request'
continue-on-error: true
run: |
echo '## E2E Test Coverage Report' >> coverage-report.txt
echo '## Test Coverage Report' >> coverage-report.txt
echo 'commit-id: ${{ github.event.pull_request.head.sha }}' >> coverage-report.txt
echo 'generated by https://github.com/vladopajic/go-test-coverage' >> coverage-report.txt
echo >> coverage-report.txt
echo '<details><summary>Additional details and impacted files</summary>' >> coverage-report.txt
echo >> coverage-report.txt
echo '```' >> coverage-report.txt
make check-e2e-coverage >> coverage-report.txt
make check-coverage >> coverage-report.txt
echo '```' >> coverage-report.txt
echo >> coverage-report.txt
echo '</details>' >> coverage-report.txt
Expand Down
12 changes: 9 additions & 3 deletions .testcoverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ exclude:
- \.pb\.gw\.go$ # excludes all protobuf generated files
- .*_mocks.go$ # excludes all protobuf generated files
- testutil/.*
- e2e/.*
- e2e/.*
- types/.*
- sdk/.*
- internal/sequence/.*

- x/types/.*
- .*/simulation/.*
- .*/module.go
- .*/module_simulation.go

# NOTES:
# - symbol `/` in all path regexps will be replaced by
# current OS file path separator to properly work on Windows
# current OS file path separator to properly work on Windows
21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: build build-linux build-macos build-windows
.PHONY: tools proto-gen proto-format test e2e_test ci lint
.PHONY: tools proto-gen proto-format test e2e_init_localchain e2e_test ci lint
.PHONY: install-go-test-coverage check-coverage

VERSION=$(shell git describe --tags --always)
Expand Down Expand Up @@ -48,22 +48,23 @@ docker-image:
go mod vendor # temporary, should be removed after open source
docker build . -t ${IMAGE_NAME}

test:
unit_test:
go test -failfast $$(go list ./... | grep -v e2e | grep -v sdk)

e2e_start_localchain:
bash ./deployment/localup/localup.sh all 1 7
e2e_init_localchain: build
bash ./deployment/localup/localup.sh init 1 7
bash ./deployment/localup/localup.sh generate 1 7

e2e_stop_localchain:
bash ./deployment/localup/localup.sh stop
e2e_test: e2e_init_localchain
go test -p 1 -failfast -v ./e2e/... -timeout 99999s

e2e_test:
go test -p 1 -failfast -v ./e2e/... -coverpkg=./... -covermode=atomic -coverprofile=./coverage.out -timeout 99999s
test: e2e_init_localchain
go test -p 1 -failfast -v $$(go list ./... | grep -v sdk) -coverpkg=./... -covermode=atomic -coverprofile=./coverage.out -timeout 99999s

install-go-test-coverage:
@go install github.com/vladopajic/go-test-coverage/v2@latest

check-e2e-coverage: install-go-test-coverage
check-coverage: install-go-test-coverage
@go-test-coverage --config=./.testcoverage.yml || true

lint:
Expand All @@ -73,5 +74,5 @@ lint:
proto-gen-check: proto-gen
git diff --exit-code

ci: proto-format-check build test e2e_start_localchain e2e_test lint proto-gen-check
ci: proto-format-check build test e2e_init_localchain e2e_test lint proto-gen-check
echo "ci passed"
72 changes: 72 additions & 0 deletions e2e/core/basesuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import (
"math"
"strconv"
"strings"
"sync"
"time"

sdkmath "cosmossdk.io/math"
"github.com/cometbft/cometbft/crypto/tmhash"
tmlog "github.com/cometbft/cometbft/libs/log"
sdkClient "github.com/cosmos/cosmos-sdk/client"
sdkServer "github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/types/tx"
Expand All @@ -22,8 +26,10 @@ import (
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/prysmaticlabs/prysm/crypto/bls"
"github.com/spf13/cobra"
"github.com/stretchr/testify/suite"

"github.com/bnb-chain/greenfield/cmd/gnfd/cmd"
"github.com/bnb-chain/greenfield/sdk/client"
"github.com/bnb-chain/greenfield/sdk/keys"
"github.com/bnb-chain/greenfield/sdk/types"
Expand All @@ -43,6 +49,8 @@ type StorageProvider struct {
GlobalVirtualGroupFamilies map[uint32][]*virtualgroupmoduletypes.GlobalVirtualGroup
}

var initValidatorOnce sync.Once

type BaseSuite struct {
suite.Suite
Config *Config
Expand All @@ -55,8 +63,72 @@ type BaseSuite struct {
StorageProviders map[uint32]*StorageProvider
}

func findCommand(cmd *cobra.Command, name string) *cobra.Command {
if len(cmd.Commands()) == 0 {
return nil
}
for _, subCmd := range cmd.Commands() {
if subCmd.Name() == name {
return subCmd
}
if found := findCommand(subCmd, name); found != nil {
return found
}
}

return nil
}

func (s *BaseSuite) InitChain() {
s.T().Log("Initializing chain")
rootCmd, _ := cmd.NewRootCmd()
// Initialize and start chain
ctx := context.Background()
srvCtx := sdkServer.NewDefaultContext()
ctx = context.WithValue(ctx, sdkClient.ClientContextKey, &sdkClient.Context{})
ctx = context.WithValue(ctx, sdkServer.ServerContextKey, srvCtx)

// if you want to debug with chain logs, please discard this
startCmd := findCommand(rootCmd, "start")
startCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
err := rootCmd.PersistentPreRunE(cmd, args)
if err != nil {
return err
}
ctx := cmd.Context()
serverCtx := sdkServer.GetServerContextFromCmd(cmd)
serverCtx.Logger = tmlog.NewNopLogger()
ctx = context.WithValue(ctx, sdkServer.ServerContextKey, serverCtx)
cmd.SetContext(ctx)
return nil
}
rootCmd.SetArgs([]string{
"start",
"--home", s.Config.ValidatorHomeDir,
"--rpc.laddr", s.Config.ValidatorTmRPCAddr,
})

errChan := make(chan error)
go func() {
errChan <- rootCmd.ExecuteContext(ctx)
}()

select {
case err := <-errChan:
s.Require().NoError(err)
case <-time.After(15 * time.Second):
// wait 15 seconds for the server to start if no errors
}

s.T().Log("Chain started")
}

func (s *BaseSuite) SetupSuite() {
s.Config = InitConfig()
initValidatorOnce.Do(func() {
s.InitChain()
})

s.Client, _ = client.NewGreenfieldClient(s.Config.TendermintAddr, s.Config.ChainId)
tmClient := client.NewTendermintClient(s.Config.TendermintAddr)
s.TmClient = &tmClient
Expand Down
14 changes: 14 additions & 0 deletions e2e/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type Config struct {
SPMnemonics []SPMnemonics `yaml:"SPMnemonics"`
SPBLSMnemonic []string `yaml:"SPBLSMnemonic"`
Denom string `yaml:"Denom"`
ValidatorHomeDir string `yaml:"ValidatorHomeDir"`
ValidatorTmRPCAddr string `yaml:"ValidatorTmRPCAddr"`
}

func InitConfig() *Config {
Expand All @@ -43,6 +45,8 @@ func InitE2eConfig() *Config {
ValidatorBlsMnemonic: ParseValidatorBlsMnemonic(0),
RelayerMnemonic: ParseRelayerMnemonic(0),
ChallengerMnemonic: ParseChallengerMnemonic(0),
ValidatorHomeDir: ParseValidatorHomeDir(0),
ValidatorTmRPCAddr: ParseValidatorTmRPCAddrDir(0),
}
for i := 0; i < 7; i++ {
config.SPMnemonics = append(config.SPMnemonics, ParseSPMnemonics(i))
Expand Down Expand Up @@ -105,3 +109,13 @@ func ParseMnemonicFromFile(fileName string) string {
}
return line
}

// ParseValidatorHomeDir returns the home dir of the validator
func ParseValidatorHomeDir(i int) string {
return fmt.Sprintf("../../deployment/localup/.local/validator%d", i)
}

// ParseValidatorTmRPCAddrDir returns the home dir of the validator
func ParseValidatorTmRPCAddrDir(i int) string {
return fmt.Sprintf("tcp://0.0.0.0:%d", 26750+i)
}
42 changes: 42 additions & 0 deletions e2e/tests/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (
"time"

sdkmath "cosmossdk.io/math"
sdkClient "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crosschaintypes "github.com/cosmos/cosmos-sdk/x/crosschain/types"
Expand All @@ -23,6 +26,7 @@ import (
"github.com/bnb-chain/greenfield/e2e/core"
gnfdtypes "github.com/bnb-chain/greenfield/sdk/types"
types2 "github.com/bnb-chain/greenfield/sdk/types"
"github.com/bnb-chain/greenfield/x/bridge/client/cli"
bridgetypes "github.com/bnb-chain/greenfield/x/bridge/types"
)

Expand All @@ -36,6 +40,44 @@ func (s *BridgeTestSuite) SetupSuite() {

func (s *BridgeTestSuite) SetupTest() {}

func (s *BridgeTestSuite) TestCliQuery() {
ctx := context.Background()
cliCtx := &sdkClient.Context{Client: s.TmClient.TmClient, Codec: s.Client.GetCodec()}
ctx = context.WithValue(ctx, sdkClient.ClientContextKey, cliCtx)
queryCmd := cli.GetQueryCmd()

// query params
queryCmd.SetArgs([]string{"params"})
s.Require().NoError(queryCmd.ExecuteContext(ctx))
}

func (s *BridgeTestSuite) TestCliTx() {
ctx := context.Background()
txCfg := authtx.NewTxConfig(s.Client.GetCodec(), []signing.SignMode{signing.SignMode_SIGN_MODE_EIP_712})
cliCtx := &sdkClient.Context{
FromAddress: s.Validator.GetAddr(),
Client: s.TmClient.TmClient,
InterfaceRegistry: s.Client.GetCodec().InterfaceRegistry(),
Codec: s.Client.GetCodec(),
From: s.Validator.String(),
AccountRetriever: authtypes.AccountRetriever{},
ChainID: s.Config.ChainId,
TxConfig: txCfg,
SkipConfirm: true,
Simulate: true,
}
ctx = context.WithValue(ctx, sdkClient.ClientContextKey, cliCtx)
txCmd := cli.GetTxCmd()

// wrong to address
txCmd.SetArgs([]string{"transfer-out", "test", "1000000000000000000BNB"})
s.Require().Contains(txCmd.ExecuteContext(ctx).Error(), "invalid address hex length")

// tx transfer-out
txCmd.SetArgs([]string{"transfer-out", sdk.AccAddress("test").String(), "1000000000000000000BNB"})
s.Require().NoError(txCmd.ExecuteContext(ctx))
}

func (s *BridgeTestSuite) TestTransferOut() {
users := s.GenAndChargeAccounts(2, 1000000)

Expand Down
5 changes: 5 additions & 0 deletions e2e/tests/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3009,6 +3009,8 @@ func (s *PaymentTestSuite) TestDiscontinue_InBlocks_WithPriceChangeReserveTimeCh
s.Require().Equal(queryHeadObjectResponse.ObjectInfo.ObjectStatus, storagetypes.OBJECT_STATUS_CREATED)
time.Sleep(200 * time.Millisecond)
}
userStreamRecord := s.getStreamRecord(user.GetAddr().String())
s.Require().True(userStreamRecord.LockBalance.IsPositive())

// update new price
msgUpdatePrice := &sptypes.MsgUpdateSpStoragePrice{
Expand Down Expand Up @@ -3107,6 +3109,9 @@ func (s *PaymentTestSuite) TestDiscontinue_InBlocks_WithPriceChangeReserveTimeCh
s.Require().Equal(streamRecordsAfter.GVG.NetflowRate.Sub(streamRecordsBefore.GVG.NetflowRate).Int64(), int64(0))
s.Require().True(streamRecordsAfter.Tax.NetflowRate.Sub(streamRecordsBefore.Tax.NetflowRate).Int64() <= int64(0)) // there are other auto settling

s.Require().True(streamRecordsAfter.User.LockBalance.IsZero())
s.Require().True(streamRecordsAfter.User.StaticBalance.Int64() == userStreamRecord.LockBalance.Int64())

// revert price
msgUpdatePrice = &sptypes.MsgUpdateSpStoragePrice{
SpAddress: sp.OperatorKey.GetAddr().String(),
Expand Down
13 changes: 13 additions & 0 deletions e2e/tests/virtualgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ func (s *VirtualGroupTestSuite) queryGlobalVirtualGroupByFamily(familyID uint32)
return resp.GlobalVirtualGroups
}

func (s *VirtualGroupTestSuite) queryAvailableGlobalVirtualGroupFamilies(familyIds []uint32) []uint32 {
resp, err := s.Client.AvailableGlobalVirtualGroupFamilies(
context.Background(),
&virtualgroupmoduletypes.AvailableGlobalVirtualGroupFamiliesRequest{
GlobalVirtualGroupFamilyIds: familyIds,
})
s.Require().NoError(err)
return resp.GlobalVirtualGroupFamilyIds
}

func (s *VirtualGroupTestSuite) TestBasic() {
primarySP := s.BaseSuite.PickStorageProvider()

Expand All @@ -82,6 +92,9 @@ func (s *VirtualGroupTestSuite) TestBasic() {
gvg = g
}

availableGvgFamilyIds := s.queryAvailableGlobalVirtualGroupFamilies([]uint32{gvg.FamilyId})
s.Require().Equal(availableGvgFamilyIds[0], gvg.FamilyId)

srcGVGs := s.queryGlobalVirtualGroupByFamily(gvg.FamilyId)

var secondarySPIDs []uint32
Expand Down
Loading