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

Add config into network information API #381

Merged
merged 1 commit into from
Dec 19, 2023
Merged
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
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)
}