mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
Add config into network information API (#381)
This commit is contained in:
parent
d249d30201
commit
e30d909643
2 changed files with 39 additions and 0 deletions
|
|
@ -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"
|
||||
)
|
||||
|
|
@ -53,6 +54,7 @@ type NetworkInformation struct {
|
|||
XDCXListingAddress common.Address
|
||||
XDCZAddress common.Address
|
||||
LendingAddress common.Address
|
||||
ConsensusConfigs params.XDPoSConfig
|
||||
}
|
||||
|
||||
type SignerTypes struct {
|
||||
|
|
@ -278,6 +280,8 @@ func (api *API) NetworkInformation() NetworkInformation {
|
|||
info.XDCXListingAddress = common.XDCXListingSMC
|
||||
info.XDCZAddress = common.TRC21IssuerSMC
|
||||
}
|
||||
info.ConsensusConfigs = *api.XDPoS.config
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
|
|
|
|||
35
consensus/tests/api_test.go
Normal file
35
consensus/tests/api_test.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
Loading…
Reference in a new issue