Skip to content

Commit

Permalink
Add config into network information API (ethereum#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrjerome authored Dec 19, 2023
1 parent d249d30 commit e30d909
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions consensus/XDPoS/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/consensus"
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/params"
"github.com/XinFinOrg/XDPoSChain/rlp"
"github.com/XinFinOrg/XDPoSChain/rpc"
)
Expand Down Expand Up @@ -53,6 +54,7 @@ type NetworkInformation struct {
XDCXListingAddress common.Address
XDCZAddress common.Address
LendingAddress common.Address
ConsensusConfigs params.XDPoSConfig
}

type SignerTypes struct {
Expand Down Expand Up @@ -278,6 +280,8 @@ func (api *API) NetworkInformation() NetworkInformation {
info.XDCXListingAddress = common.XDCXListingSMC
info.XDCZAddress = common.TRC21IssuerSMC
}
info.ConsensusConfigs = *api.XDPoS.config

return info
}

Expand Down
35 changes: 35 additions & 0 deletions consensus/tests/api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tests

import (
"math/big"
"testing"

"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind/backends"
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
"github.com/XinFinOrg/XDPoSChain/core"
"github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/params"
"github.com/stretchr/testify/assert"
)

var (
voterKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee04aefe388d1e14474d32c45c72ce7b7a")
voterAddr = crypto.PubkeyToAddress(voterKey.PublicKey) //xdc5F74529C0338546f82389402a01c31fB52c6f434
)

func TestConfigApi(t *testing.T) {

bc := backends.NewXDCSimulatedBackend(core.GenesisAlloc{
voterAddr: {Balance: new(big.Int).SetUint64(10000000000)},
}, 10000000, params.TestXDPoSMockChainConfig)

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.MaxMasternodes, 18)
assert.Equal(t, info.ConsensusConfigs.V2.CurrentConfig.CertThreshold, 0.667)
assert.Equal(t, info.ConsensusConfigs.V2.CurrentConfig.MinePeriod, 2)
assert.Equal(t, info.ConsensusConfigs.V2.CurrentConfig.TimeoutSyncThreshold, 2)
}

0 comments on commit e30d909

Please sign in to comment.