Skip to content

Commit

Permalink
Merge branch 'master' into fix-unit-tests-more
Browse files Browse the repository at this point in the history
  • Loading branch information
devfans authored Oct 12, 2023
2 parents 143a3bc + d364dfb commit 261083a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on: [push , pull_request]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

# - name: Run init
# run: go run build/ci.go lint

- name: Build
run: make geth

- name: Test
run: go test -timeout=40m -tags=ckzg -p 1 ./...
1 change: 1 addition & 0 deletions consensus/hotstuff/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (c *core) Stop() {
c.stopTimer()
c.isRunning = false
close(c.exit)

c.wg.Wait()
}

Expand Down
2 changes: 2 additions & 0 deletions contracts/native/governance/entrance.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func AssembleSystemTransactions(state *state.StateDB, height uint64) (types.Tran
if err != nil {
return nil, err
}

gas, err := core.IntrinsicGas(payload, nil, false, true, true)
if err != nil {
return nil, err
Expand All @@ -66,6 +67,7 @@ func AssembleSystemTransactions(state *state.StateDB, height uint64) (types.Tran
if err != nil {
return nil, err
}

gas, err := core.IntrinsicGas(payload, nil, false, true, true)
if err != nil {
return nil, err
Expand Down
38 changes: 38 additions & 0 deletions contracts/native/governance/node_manager/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,41 @@ func StoreGenesisGlobalConfig(s *state.StateDB) error {
}
return nil
}

func StoreGenesisEpochForTest(s *state.StateDB, peers []common.Address, signers []common.Address,
blockPerEpoch *big.Int) (*EpochInfo, error) {
cache := (*state.CacheDB)(s)
epoch := &EpochInfo{
ID: StartEpochID,
Validators: peers,
Signers: signers,
Voters: signers,
Proposers: signers,
StartHeight: new(big.Int),
EndHeight: blockPerEpoch,
}

// store current epoch and epoch info
if err := setGenesisEpochInfo(cache, epoch); err != nil {
return nil, err
}
return epoch, nil
}

func StoreGenesisGlobalConfigForTest(s *state.StateDB, blockPerEpoch *big.Int) error {
cache := (*state.CacheDB)(s)
globalConfig := &GlobalConfig{
MaxCommissionChange: GenesisMaxCommissionChange,
MinInitialStake: GenesisMinInitialStake,
MinProposalStake: GenesisMinProposalStake,
BlockPerEpoch: blockPerEpoch,
ConsensusValidatorNum: GenesisConsensusValidatorNum,
VoterValidatorNum: GenesisVoterValidatorNum,
}

// store current epoch and epoch info
if err := setGenesisGlobalConfig(cache, globalConfig); err != nil {
return err
}
return nil
}
14 changes: 10 additions & 4 deletions contracts/native/governance/node_manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/contracts/native"
"github.com/ethereum/go-ethereum/contracts/native/contract"

Check failure on line 32 in contracts/native/governance/node_manager/manager_test.go

View workflow job for this annotation

GitHub Actions / build

contract redeclared in this block

Check failure on line 32 in contracts/native/governance/node_manager/manager_test.go

View workflow job for this annotation

GitHub Actions / build

"github.com/ethereum/go-ethereum/contracts/native/contract" imported and not used
. "github.com/ethereum/go-ethereum/contracts/native/go_abi/node_manager_abi"
"github.com/ethereum/go-ethereum/contracts/native/governance/community"

Check failure on line 34 in contracts/native/governance/node_manager/manager_test.go

View workflow job for this annotation

GitHub Actions / build

community redeclared in this block

Check failure on line 34 in contracts/native/governance/node_manager/manager_test.go

View workflow job for this annotation

GitHub Actions / build

"github.com/ethereum/go-ethereum/contracts/native/governance/community" imported and not used
"github.com/ethereum/go-ethereum/contracts/native/utils"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -72,7 +74,7 @@ func TestCheckGenesis(t *testing.T) {

globalConfig, err := GetGlobalConfigImpl(contract)
assert.Nil(t, err)
assert.Equal(t, globalConfig.BlockPerEpoch, GenesisBlockPerEpoch)
assert.Equal(t, globalConfig.BlockPerEpoch, big.NewInt(400000))
assert.Equal(t, globalConfig.MaxCommissionChange, GenesisMaxCommissionChange)
assert.Equal(t, globalConfig.MinInitialStake, GenesisMinInitialStake)
assert.Equal(t, globalConfig.VoterValidatorNum, GenesisVoterValidatorNum)
Expand All @@ -96,7 +98,7 @@ func TestCheckGenesis(t *testing.T) {
globalConfig2 := new(GlobalConfig)
err = globalConfig2.Decode(ret)
assert.Nil(t, err)
assert.Equal(t, globalConfig2.BlockPerEpoch, GenesisBlockPerEpoch)
assert.Equal(t, globalConfig2.BlockPerEpoch, big.NewInt(400000))
assert.Equal(t, globalConfig2.MaxCommissionChange, GenesisMaxCommissionChange)
assert.Equal(t, globalConfig2.MinInitialStake, GenesisMinInitialStake)
assert.Equal(t, globalConfig2.VoterValidatorNum, GenesisVoterValidatorNum)
Expand Down Expand Up @@ -132,7 +134,7 @@ func TestCheckGenesis(t *testing.T) {

globalConfig, err = GetGlobalConfigFromDB(sdb)
assert.Nil(t, err)
assert.Equal(t, globalConfig.BlockPerEpoch, GenesisBlockPerEpoch)
assert.Equal(t, globalConfig.BlockPerEpoch, big.NewInt(400000))
}

func TestStake(t *testing.T) {
Expand Down Expand Up @@ -602,6 +604,7 @@ func TestDistribute(t *testing.T) {
// first add 1000 balance of node_manager contract to distribute
sdb.AddBalance(utils.NodeManagerContractAddress, new(big.Int).Mul(big.NewInt(1000), params.ZNT1))
// call endblock
sdb.SubBalance(utils.NodeManagerContractAddress, big.NewInt(800000000000000000))
param3 := new(EndBlockParam)
input, err = param3.Encode()
assert.Nil(t, err)
Expand Down Expand Up @@ -892,6 +895,7 @@ func TestDistribute(t *testing.T) {
// add 2000 balance of node_manager contract to distribute
sdb.AddBalance(utils.NodeManagerContractAddress, new(big.Int).Mul(big.NewInt(1000), params.ZNT1))
// call endblock
sdb.SubBalance(utils.NodeManagerContractAddress, big.NewInt(800000000000000000))
param9 := new(EndBlockParam)
input, err = param9.Encode()
assert.Nil(t, err)
Expand All @@ -901,6 +905,7 @@ func TestDistribute(t *testing.T) {

sdb.AddBalance(utils.NodeManagerContractAddress, new(big.Int).Mul(big.NewInt(1000), params.ZNT1))
// call endblock
sdb.SubBalance(utils.NodeManagerContractAddress, big.NewInt(800000000000000000))
param10 := new(EndBlockParam)
input, err = param10.Encode()
assert.Nil(t, err)
Expand Down Expand Up @@ -962,7 +967,7 @@ func TestDistribute(t *testing.T) {
b7, _ := new(big.Int).SetString("1000092307692307692280000", 10)
assert.Equal(t, sdb.GetBalance(stakeAddress), b6)
assert.Equal(t, sdb.GetBalance(stakeAddress2), b7)
assert.Equal(t, sdb.GetBalance(common.EmptyAddress), new(big.Int).SetUint64(180000))
assert.Equal(t, sdb.GetBalance(common.EmptyAddress), new(big.Int).SetUint64(600000000000180000))
_, found, err := getValidator(contractQuery, validatorsKey[0].ConsensusAddr)
assert.Nil(t, err)
assert.Equal(t, found, false)
Expand Down Expand Up @@ -1028,6 +1033,7 @@ func TestPerformance(t *testing.T) {
assert.Nil(t, err)

// call endblock
sdb.SubBalance(utils.NodeManagerContractAddress, big.NewInt(800000000000000000))
sdb.AddBalance(utils.NodeManagerContractAddress, new(big.Int).Mul(big.NewInt(10000000), params.ZNT1))
param := new(EndBlockParam)
input, err = param.Encode()
Expand Down
1 change: 1 addition & 0 deletions ethclient/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ func sendTransaction(ec *Client) error {
Gas: 22000,
GasPrice: big.NewInt(params.InitialBaseFee),
})

if err != nil {
return err
}
Expand Down

0 comments on commit 261083a

Please sign in to comment.