Skip to content

Commit

Permalink
addin consts
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Jul 25, 2024
1 parent 1bd0937 commit 8159df2
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 96 deletions.
10 changes: 10 additions & 0 deletions consts/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package consts

import (
"github.com/ethereum/go-ethereum/common/hexutil"
"math/big"
)

var (
LargeBigValue = new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))
)
68 changes: 37 additions & 31 deletions environments/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,45 @@ func TestDockerNetwork(t *testing.T) {
networkCfg := &network.Network{
Environment: "docker",
ID: "test-id",
Nodes: []*node.Node{
{
ID: "node1",
ExecArtifact: "vechain/thor:latest",
Genesis: preset.LocalThreeMasterNodesNetworkGenesis,
DataDir: "/home/thor",
ConfigDir: "/home/thor",
APIAddr: "0.0.0.0:8545",
APICORS: "*",
P2PListenPort: 30303,
Key: preset.LocalThreeMasterNodesNetwork.Nodes[0].Key,
Nodes: []node.Node{
&node.NodePreCoefFork{
BaseNode: node.BaseNode{
ID: "node1",
ExecArtifact: "vechain/thor:latest",
DataDir: "/home/thor",
ConfigDir: "/home/thor",
APIAddr: "0.0.0.0:8545",
APICORS: "*",
P2PListenPort: 30303,
Key: preset.LocalThreeMasterNodesNetwork.Nodes[0].GetKey(),
},
Genesis: preset.LocalThreeMasterNodesNetworkGenesis,
},
{
ID: "node2",
ExecArtifact: "vechain/thor:latest",
Genesis: preset.LocalThreeMasterNodesNetworkGenesis,
DataDir: "/home/thor",
ConfigDir: "/home/thor",
APIAddr: "0.0.0.0:8545",
APICORS: "*",
P2PListenPort: 30303,
Key: preset.LocalThreeMasterNodesNetwork.Nodes[1].Key,
&node.NodePreCoefFork{
BaseNode: node.BaseNode{
ID: "node2",
ExecArtifact: "vechain/thor:latest",
DataDir: "/home/thor",
ConfigDir: "/home/thor",
APIAddr: "0.0.0.0:8545",
APICORS: "*",
P2PListenPort: 30303,
Key: preset.LocalThreeMasterNodesNetwork.Nodes[1].GetKey(),
},
Genesis: preset.LocalThreeMasterNodesNetworkGenesis,
},
{
ID: "node3",
ExecArtifact: "vechain/thor:latest",
Genesis: preset.LocalThreeMasterNodesNetworkGenesis,
DataDir: "/home/thor",
ConfigDir: "/home/thor",
APIAddr: "0.0.0.0:8545",
APICORS: "*",
P2PListenPort: 30303,
Key: preset.LocalThreeMasterNodesNetwork.Nodes[2].Key,
&node.NodePreCoefFork{
BaseNode: node.BaseNode{
ID: "node3",
ExecArtifact: "vechain/thor:latest",
DataDir: "/home/thor",
ConfigDir: "/home/thor",
APIAddr: "0.0.0.0:8545",
APICORS: "*",
P2PListenPort: 30303,
Key: preset.LocalThreeMasterNodesNetwork.Nodes[2].GetKey(),
},
Genesis: preset.LocalThreeMasterNodesNetworkGenesis,
},
},
}
Expand Down
18 changes: 9 additions & 9 deletions environments/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ type Local struct {
id string
}

func fileExists(path string) bool {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return false
}
return err == nil
}

func NewLocalEnv() environments.Actions {
return &Local{
localNodes: map[string]*Node{},
Expand All @@ -46,7 +38,7 @@ func (l *Local) LoadConfig(cfg *network.Network) (string, error) {

// check if the exec artifact path exists
if !fileExists(n.GetExecArtifact()) {
return "", fmt.Errorf("file does not exist at path: %s", n.GetExecArtifact())
return "", fmt.Errorf("exec does not exist at path: %s", n.GetExecArtifact())
}
}

Expand Down Expand Up @@ -90,3 +82,11 @@ func (l *Local) Info() error {
//TODO implement me
panic("implement me")
}

func fileExists(path string) bool {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return false
}
return err == nil
}
6 changes: 3 additions & 3 deletions environments/local/local_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ func (n *Node) Start() error {
}

fmt.Println(cmd)
if n.nodeCfg.GetID() == "node1" {
return nil
}
//if n.nodeCfg.GetID() == "node1" {
// return nil
//}
// Start the command and check for errors
if err := cmd.Start(); err != nil {
return fmt.Errorf("failed to start thor command: %w", err)
Expand Down
16 changes: 14 additions & 2 deletions environments/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestLocal(t *testing.T) {
}

func TestSixNodeLocal(t *testing.T) {
t.Skip()
//t.Skip()
sixNodeJson, err := json.Marshal(preset.LocalSixNodesNetwork)
require.NoError(t, err)

Expand All @@ -174,14 +174,26 @@ func TestSixNodeLocal(t *testing.T) {
)
require.NoError(t, err)

// ensure the artifact path is set
for _, node := range networkCfg.Nodes {
node.SetExecArtifact("/Users/pedro/go/src/github.com/vechain/thor/bin/thor")
}

localEnv := NewLocalEnv()
_, err = localEnv.LoadConfig(networkCfg)
require.NoError(t, err)

err = localEnv.StartNetwork()
require.NoError(t, err)

time.Sleep(5 * time.Minute)
time.Sleep(30 * time.Second) // todo change this to a polling approach
for _, node := range networkCfg.Nodes {
c := client.NewClient("http://" + node.GetAPIAddr())
peers, err := c.GetPeers()
require.NoError(t, err)

require.GreaterOrEqual(t, len(peers), 0)
}
err = localEnv.StopNetwork()
require.NoError(t, err)
}
78 changes: 39 additions & 39 deletions preset/LocalSixNodes.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package preset

import (
"github.com/vechain/networkhub/consts"
"math/big"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/vechain/networkhub/environments"
"github.com/vechain/networkhub/network"
"github.com/vechain/networkhub/network/node"
Expand All @@ -19,7 +19,7 @@ var LocalSixNodesNetwork = &network.Network{
BaseNode: node.BaseNode{
ID: "node1",
P2PListenPort: 8081,
APIAddr: "0.0.0.0:8181",
APIAddr: "127.0.0.1:8181",
APICORS: "*",
Type: node.MasterNode,
Verbosity: 4,
Expand All @@ -31,7 +31,7 @@ var LocalSixNodesNetwork = &network.Network{
BaseNode: node.BaseNode{
ID: "node2",
P2PListenPort: 8082,
APIAddr: "0.0.0.0:8182",
APIAddr: "127.0.0.1:8182",
APICORS: "*",
Type: node.MasterNode,
Verbosity: 4,
Expand All @@ -43,7 +43,7 @@ var LocalSixNodesNetwork = &network.Network{
BaseNode: node.BaseNode{
ID: "node3",
P2PListenPort: 8083,
APIAddr: "0.0.0.0:8183",
APIAddr: "127.0.0.1:8183",
APICORS: "*",
Type: node.RegularNode,
Key: "1b310ea04afd6d14a8f142158873fc70bfd4ba12a19138cc5b309fce7c77105e", // 0x1b1c0055065b3ADee4B9a9e8297142Ba2cD34EfE
Expand All @@ -54,7 +54,7 @@ var LocalSixNodesNetwork = &network.Network{
BaseNode: node.BaseNode{
ID: "node4",
P2PListenPort: 8084,
APIAddr: "0.0.0.0:8184",
APIAddr: "127.0.0.1:8184",
APICORS: "*",
Type: node.MasterNode,
Verbosity: 4,
Expand All @@ -66,7 +66,7 @@ var LocalSixNodesNetwork = &network.Network{
BaseNode: node.BaseNode{
ID: "node5",
P2PListenPort: 8085,
APIAddr: "0.0.0.0:8185",
APIAddr: "127.0.0.1:8185",
APICORS: "*",
Type: node.MasterNode,
Verbosity: 4,
Expand All @@ -78,7 +78,7 @@ var LocalSixNodesNetwork = &network.Network{
BaseNode: node.BaseNode{
ID: "node6",
P2PListenPort: 8086,
APIAddr: "0.0.0.0:8186",
APIAddr: "127.0.0.1:8186",
APICORS: "*",
Type: node.RegularNode,
Key: "92ad65923d6782a43e6a1be01a8e52bce701967d78937e73da746a58f293ba30", // 0x9C2871C411CCe579B987E9b932C484dA8b901075
Expand All @@ -95,7 +95,7 @@ var localSixNodesNetworkGenesis = &genesis.CustomGenesis{
Accounts: []genesis.Account{
{
Address: thor.MustParseAddress("0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(big.NewInt(0)),
Code: "0x6060604052600256",
Storage: map[string]thor.Bytes32{
Expand All @@ -104,78 +104,78 @@ var localSixNodesNetworkGenesis = &genesis.CustomGenesis{
},
{
Address: thor.MustParseAddress("0x5F90f56c7b87E3d1acf9437f0E43E4d687AcEB7e"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
{
Address: thor.MustParseAddress("0x5c29518F6a6124a2BeE89253347c8295f604710A"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
{
Address: thor.MustParseAddress("0x1b1c0055065b3ADee4B9a9e8297142Ba2cD34EfE"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
{
Address: thor.MustParseAddress("0x042306e116Dc301ecd7b83a04F4c8277Fbe41b6c"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
{
Address: thor.MustParseAddress("0x0aeC31606e217895696771961de416Efa185Be66"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
{
Address: thor.MustParseAddress("0xf077b491b355E64048cE21E3A6Fc4751eEeA77fa"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
{
Address: thor.MustParseAddress("0x435933c8064b4Ae76bE665428e0307eF2cCFBD68"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},

{
Address: thor.MustParseAddress("0x0F872421Dc479F3c11eDd89512731814D0598dB5"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
{
Address: thor.MustParseAddress("0xF370940aBDBd2583bC80bfc19d19bc216C88Ccf0"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
{
Address: thor.MustParseAddress("0x99602e4Bbc0503b8ff4432bB1857F916c3653B85"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
{
Address: thor.MustParseAddress("0x61E7d0c2B25706bE3485980F39A3a994A8207aCf"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
{
Address: thor.MustParseAddress("0x361277D1b27504F36a3b33d3a52d1f8270331b8C"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
}, {
Address: thor.MustParseAddress("0xD7f75A0A1287ab2916848909C8531a0eA9412800"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
{
Address: thor.MustParseAddress("0xAbEf6032B9176C186F6BF984f548bdA53349f70a"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
{
Address: thor.MustParseAddress("0x865306084235Bf804c8Bba8a8d56890940ca8F0b"),
Balance: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Energy: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
},
Authority: []genesis.Authority{
Expand Down Expand Up @@ -203,7 +203,7 @@ var localSixNodesNetworkGenesis = &genesis.CustomGenesis{
Params: genesis.Params{
RewardRatio: convToHexOrDecimal256(big.NewInt(300000000000000000)),
BaseGasPrice: convToHexOrDecimal256(big.NewInt(1000000000000000)),
ProposerEndorsement: convToHexOrDecimal256(new(big.Int).SetBytes(hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),
ProposerEndorsement: convToHexOrDecimal256(consts.LargeBigValue),
ExecutorAddress: &localThreeMasterEndorser,
},
Executor: genesis.Executor{
Expand Down
Loading

0 comments on commit 8159df2

Please sign in to comment.