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

From xdpos 8 fix tests #168

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ jobs:
matrix:
include:
- name: A-B tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[a-b].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[a-b].*")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe we shall move those repeated code into its own method

- name: C-[a-m] tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[a-m].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[a-m].*")
- name: C-[n-o] tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[n-o].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[n-o].*")
- name: C-[p-z] tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[p-z].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[p-z].*")
- name: D-I tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[d-i].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[d-i].*")
- name: J-N tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[j-n].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[j-n].*")
- name: O-R tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[o-r].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[o-r].*")
- name: S tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/s.*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/s.*")
- name: T-Z tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[t-z].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[t-z].*")
steps:
- name: Check out code
uses: actions/checkout@v3
Expand Down
22 changes: 13 additions & 9 deletions .github/workflows/pr_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ on:
pull_request:
branches:
- master
#TODO: remove push trigger
push: #temporary trigger tests this way
branches:
- '*'

jobs:
test_golang:
Expand All @@ -19,23 +23,23 @@ jobs:
matrix:
include:
- name: A-B tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[a-b].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[a-b].*")
- name: C-[a-m] tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[a-m].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[a-m].*")
- name: C-[n-o] tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[n-o].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[n-o].*")
- name: C-[p-z] tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[p-z].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[p-z].*")
- name: D-I tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[d-i].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[d-i].*")
- name: J-N tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[j-n].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[j-n].*")
- name: O-R tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[o-r].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[o-r].*")
- name: S tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/s.*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/s.*")
- name: T-Z tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[t-z].*")
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[t-z].*")
steps:
- name: Check out code
uses: actions/checkout@v3
Expand Down
19 changes: 8 additions & 11 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,15 @@ var TIPV2SwitchBlock = big.NewInt(0)

var TIPNoHalvingMNReward = big.NewInt(0) // hardfork no halving masternodes reward
var BlackListHFNumber = uint64(0)
var TIPXDCX = big.NewInt(0)
var TIPXDCXLending = big.NewInt(0)
var TIPXDCXCancellationFee = big.NewInt(0)
var TIPXDCXCancellationFeeTestnet = big.NewInt(0)
var TIPXDCXDISABLE = big.NewInt(0)
var TIPXDCX = big.NewInt(38383838)
var TIPXDCXLending = big.NewInt(38383838)
var TIPXDCXCancellationFee = big.NewInt(38383838)
var TIPXDCXCancellationFeeTestnet = big.NewInt(38383838)
var TIPXDCXMinerDisable = big.NewInt(88999999900)
var TIPXDCXReceiverDisable = big.NewInt(99999999999)
var BerlinBlock = big.NewInt(9999999999)
var LondonBlock = big.NewInt(9999999999)
var MergeBlock = big.NewInt(9999999999)
var ShanghaiBlock = big.NewInt(9999999999)
var Eip1559Block = big.NewInt(9999999999)
var BerlinBlock = big.NewInt(0)
var LondonBlock = big.NewInt(0)
var MergeBlock = big.NewInt(0)
var ShanghaiBlock = big.NewInt(0)

var TIPXDCXTestnet = big.NewInt(0)
var IsTestnet bool = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ var TIPV2SwitchBlock = big.NewInt(0)

var TIPNoHalvingMNReward = big.NewInt(0) // hardfork no halving masternodes reward
var BlackListHFNumber = uint64(0)
var TIPXDCX = big.NewInt(0)
var TIPXDCXLending = big.NewInt(0)
var TIPXDCXCancellationFee = big.NewInt(0)
var TIPXDCXCancellationFeeTestnet = big.NewInt(0)
var TIPXDCXDISABLE = big.NewInt(0)
var BerlinBlock = big.NewInt(0)
var LondonBlock = big.NewInt(0)
var MergeBlock = big.NewInt(0)
var ShanghaiBlock = big.NewInt(0)
var TIPXDCX = big.NewInt(38383838)
var TIPXDCXLending = big.NewInt(38383838)
var TIPXDCXCancellationFee = big.NewInt(38383838)
var TIPXDCXCancellationFeeTestnet = big.NewInt(38383838)
var TIPXDCXMinerDisable = big.NewInt(88999999900)
var TIPXDCXReceiverDisable = big.NewInt(99999999999)
var BerlinBlock = big.NewInt(9999999999)
var LondonBlock = big.NewInt(9999999999)
var MergeBlock = big.NewInt(9999999999)
var ShanghaiBlock = big.NewInt(9999999999)
var Eip1559Block = big.NewInt(9999999999)

var TIPXDCXTestnet = big.NewInt(0)
var IsTestnet bool = false
Expand Down
1 change: 1 addition & 0 deletions consensus/XDPoS/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ func (api *API) NetworkInformation() NetworkInformation {
info.XDCValidatorAddress = common.HexToAddress(common.MasternodeVotingSMC)
info.Denom = api.chain.Config().XDPoS.Denom
info.NetworkName = api.chain.Config().XDPoS.NetworkName
info.ConsensusConfigs = *api.XDPoS.config
return info
}

Expand Down
1 change: 0 additions & 1 deletion consensus/tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func TestConfigApi(t *testing.T) {
engine := bc.GetBlockChain().Engine().(*XDPoS.XDPoS)

info := engine.APIs(bc.GetBlockChain())[0].Service.(*XDPoS.API).NetworkInformation()

assert.Equal(t, info.NetworkId, big.NewInt(1337))
assert.Equal(t, info.ConsensusConfigs.V2.CurrentConfig.CertThreshold, 0.667)
assert.Equal(t, info.ConsensusConfigs.V2.CurrentConfig.MinePeriod, 2)
Expand Down
36 changes: 12 additions & 24 deletions consensus/tests/engine_v2_tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ import (
"github.com/stretchr/testify/assert"
)

func TestGetMissedRoundsInEpochByBlockNumOnlyForV2Consensus(t *testing.T) {
_, bc, _, _, _ := PrepareXDCTestBlockChainWith128Candidates(t, 1802, params.TestXDPoSMockChainConfig)

engine := bc.GetBlockChain().Engine().(*XDPoS.XDPoS)
blockNum := rpc.BlockNumber(123)

data, err := engine.APIs(bc.GetBlockChain())[0].Service.(*XDPoS.API).GetMissedRoundsInEpochByBlockNum(&blockNum)

assert.EqualError(t, err, "Not supported in the v1 consensus")
assert.Nil(t, data)
}

func TestGetMissedRoundsInEpochByBlockNumReturnEmptyForV2(t *testing.T) {
_, bc, cb, _, _ := PrepareXDCTestBlockChainWith128Candidates(t, 1802, params.TestXDPoSMockChainConfig)

Expand All @@ -32,7 +20,7 @@ func TestGetMissedRoundsInEpochByBlockNumReturnEmptyForV2(t *testing.T) {
data, err := engine.APIs(bc.GetBlockChain())[0].Service.(*XDPoS.API).GetMissedRoundsInEpochByBlockNum(&blockNum)

assert.Nil(t, err)
assert.Equal(t, types.Round(900), data.EpochRound)
assert.Equal(t, types.Round(1800), data.EpochRound)
assert.Equal(t, big.NewInt(1800), data.EpochBlockNumber)
assert.Equal(t, 0, len(data.MissedRounds))

Expand All @@ -41,7 +29,7 @@ func TestGetMissedRoundsInEpochByBlockNumReturnEmptyForV2(t *testing.T) {
data, err = engine.APIs(bc.GetBlockChain())[0].Service.(*XDPoS.API).GetMissedRoundsInEpochByBlockNum(&blockNum)

assert.Nil(t, err)
assert.Equal(t, types.Round(900), data.EpochRound)
assert.Equal(t, types.Round(1800), data.EpochRound)
assert.Equal(t, big.NewInt(1800), data.EpochBlockNumber)
assert.Equal(t, 0, len(data.MissedRounds))

Expand All @@ -50,22 +38,22 @@ func TestGetMissedRoundsInEpochByBlockNumReturnEmptyForV2(t *testing.T) {
data, err = engine.APIs(bc.GetBlockChain())[0].Service.(*XDPoS.API).GetMissedRoundsInEpochByBlockNum(&blockNum)

assert.Nil(t, err)
assert.Equal(t, types.Round(900), data.EpochRound)
assert.Equal(t, types.Round(1800), data.EpochRound)
assert.Equal(t, big.NewInt(1800), data.EpochBlockNumber)
assert.Equal(t, 0, len(data.MissedRounds))
}

func TestGetMissedRoundsInEpochByBlockNumReturnEmptyForV2FistEpoch(t *testing.T) {
_, bc, _, _, _ := PrepareXDCTestBlockChainWith128Candidates(t, 1802, params.TestXDPoSMockChainConfig)
_, bc, _, _, _ := PrepareXDCTestBlockChainWith128Candidates(t, 10, params.TestXDPoSMockChainConfig)

engine := bc.GetBlockChain().Engine().(*XDPoS.XDPoS)
blockNum := rpc.BlockNumber(901)
blockNum := rpc.BlockNumber(2)

data, err := engine.APIs(bc.GetBlockChain())[0].Service.(*XDPoS.API).GetMissedRoundsInEpochByBlockNum(&blockNum)

assert.Nil(t, err)
assert.Equal(t, types.Round(1), data.EpochRound)
assert.Equal(t, big.NewInt(901), data.EpochBlockNumber)
assert.Equal(t, types.Round(0), data.EpochRound)
assert.Equal(t, big.NewInt(0), data.EpochBlockNumber)
assert.Equal(t, 0, len(data.MissedRounds))
}

Expand All @@ -77,8 +65,8 @@ func TestGetMissedRoundsInEpochByBlockNum(t *testing.T) {

startingBlockNum := currentBlock.Number().Int64() + 1
// Skipped the round
roundNumber := startingBlockNum - chainConfig.XDPoS.V2.SwitchBlock.Int64() + 2
block := CreateBlock(blockchain, chainConfig, currentBlock, int(startingBlockNum), roundNumber, blockCoinBase, signer, signFn, nil, nil, "b345a8560bd51926803dd17677c9f0751193914a851a4ec13063d6bf50220b53")
roundNumber := startingBlockNum + 2
block := CreateBlock(blockchain, chainConfig, currentBlock, int(startingBlockNum), roundNumber, blockCoinBase, signer, signFn, nil, nil, "c2bf7b59be5184fc1148be5db14692b2dc89a1b345895d3e8d0ee7b8a7607450")
err := blockchain.InsertBlock(block)
if err != nil {
t.Fatal(err)
Expand All @@ -95,15 +83,15 @@ func TestGetMissedRoundsInEpochByBlockNum(t *testing.T) {
data, err := engine.APIs(bc.GetBlockChain())[0].Service.(*XDPoS.API).GetMissedRoundsInEpochByBlockNum(&blockNum)

assert.Nil(t, err)
assert.Equal(t, types.Round(900), data.EpochRound)
assert.Equal(t, types.Round(1800), data.EpochRound)
assert.Equal(t, big.NewInt(1800), data.EpochBlockNumber)
assert.Equal(t, 2, len(data.MissedRounds))
assert.NotEmpty(t, data.MissedRounds[0].Miner)
assert.Equal(t, data.MissedRounds[0].Round, types.Round(903))
assert.Equal(t, data.MissedRounds[0].Round, types.Round(1803))
assert.Equal(t, data.MissedRounds[0].CurrentBlockNum, big.NewInt(1803))
assert.Equal(t, data.MissedRounds[0].ParentBlockNum, big.NewInt(1802))
assert.NotEmpty(t, data.MissedRounds[1].Miner)
assert.Equal(t, data.MissedRounds[1].Round, types.Round(904))
assert.Equal(t, data.MissedRounds[1].Round, types.Round(1804))
assert.Equal(t, data.MissedRounds[0].CurrentBlockNum, big.NewInt(1803))
assert.Equal(t, data.MissedRounds[0].ParentBlockNum, big.NewInt(1802))

Expand Down
2 changes: 1 addition & 1 deletion consensus/tests/engine_v2_tests/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ func PrepareXDCTestBlockChainWith128Candidates(t *testing.T, numOfBlocks int, ch
t.Fatal(err)
}

//FROM XDPOS v1 block: prob don't need in subnet
//FROM XDPOS: find v2 switch block, don't need in subnet
// First v2 block
// if (int64(i) - chainConfig.XDPoS.V2.SwitchBlock.Int64()) == 1 {
// lastv1BlockNumber := block.Header().Number.Uint64() - 1
Expand Down
8 changes: 4 additions & 4 deletions consensus/tests/engine_v2_tests/verify_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,17 @@ func TestConfigSwitchOnDifferentMasternodeCount(t *testing.T) {

snap, err := x.GetSnapshot(blockchain, currentBlock.Header())
assert.Nil(t, err)
assert.Equal(t, len(snap.NextEpochMasterNodes), 20)
assert.Equal(t, len(snap.NextEpochMasterNodes), 5)
header1800.Validators = []common.Address{}
for i := 0; i < 20; i++ {
for i := 0; i < len(snap.NextEpochMasterNodes); i++ {
header1800.Validators = append(header1800.Validators, []common.Address{snap.NextEpochMasterNodes[i]}...)
}

round, err := x.GetRoundNumber(header1800)
assert.Nil(t, err)
assert.Equal(t, round, types.Round(900))
assert.Equal(t, round, types.Round(1800))

adaptor.EngineV2.SetNewRoundFaker(blockchain, 899, false)
adaptor.EngineV2.SetNewRoundFaker(blockchain, 1799, false)

err = adaptor.VerifyHeader(blockchain, header1800, true)

Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ RUN apt-get update && apt-get install -y git build-essential
COPY . /builder

RUN go env -w GOFLAGS="-buildvcs=false"
RUN mv /builder/common/constants/constants.go.custom /builder/common/constants.go
RUN cd /builder && make XDC && make bootnode && make puppeth

# The actual image for subnet containers
Expand Down
Loading