-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup_environment_test.go
181 lines (145 loc) · 4.96 KB
/
setup_environment_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package main
import (
"fmt"
"github.com/cucumber/godog"
"github.com/ethereum/go-ethereum/common"
"log"
)
var platformContractsDir string
var exampleServiceDir string
var treasurerServerDir string
var snetConfigFile string
var snetIdentityAddress string
var singnetTokenAddress string
var registryAddress string
var multiPartyEscrow string
var organizationAddress string
func init() {
platformContractsDir = envSingnetRepos + "/platform-contracts"
exampleServiceDir = envSingnetRepos + "/example-service"
treasurerServerDir = envSingnetRepos + "/treasurer"
snetConfigFile = envHome + "/.snet/config"
}
func ethereumNetworkIsRunningOnPort(port int) (err error) {
output := logPath + "/ganache.log"
NewCommand().Run("killall node || echo \"supress an error\"")
NewCommand().Run("killall etcd || echo \"supress an error\"")
err = NewCommand().Dir(platformContractsDir).
Output(output).
RunAsync("./node_modules/.bin/ganache-cli --deterministic --mnemonic \"gauge enact biology destroy normal tunnel slight slide wide sauce ladder produce\"").
CheckOutput("Listening on 127.0.0.1:" + toString(port)).
Err()
if err != nil {
return
}
return initAddresses(output)
}
func toChecksumAddress(hexAddress string) string {
address := common.HexToAddress(hexAddress)
mixedAddress := common.NewMixedcaseAddress(address)
return mixedAddress.Address().String()
}
func initAddresses(output string) (err error) {
snetIdentityAddress, err = getPropertyFromFile(output, "(0)")
if err != nil {
return
}
snetIdentityAddress = toChecksumAddress(snetIdentityAddress)
organizationAddress, err = getPropertyFromFile(output, "(1)")
if err != nil {
return
}
organizationAddress = toChecksumAddress(organizationAddress)
return
}
func contractsAreDeployedUsingTruffle() (err error) {
output := logPath + "/migrate.out"
err = NewCommand().
Dir(platformContractsDir).
Run("./node_modules/.bin/truffle compile").
Output(output).
Run("./node_modules/.bin/truffle migrate --network local").
Err()
if err != nil {
return
}
return initContractAddresses(output)
}
func initContractAddresses(output string) (err error) {
//we need to re write the code to determine the address as the file output has significantly changed
singnetTokenAddress = "0x6E5F20669177F5bDf3703EC5eA9c4d4Fe3aAbd14" /*, err = getPropertyFromFile(output, "address")
if err != nil {
return
}*/
registryAddress = "0x4E74FefA82E83E0964f0D9f53c68e03f7298a8b2" /*, err = getPropertyFromFile(output, "Registry")
if err != nil {
return
}
*/
multiPartyEscrow = "0x5C7a4290F6F8FF64c69eEffDFAFc8644A4Ec3a4E" /*, err = getPropertyFromFile(output, "MultiPartyEscrow")
if err != nil {
return
}
*/
return
}
func ipfsIsRunning(portAPI int, portGateway int) (err error) {
fmt.Println("ipfsIsRunning")
addressAPI := "/ip4/127.0.0.1/tcp/" + toString(portAPI)
addressGateway := "/ip4/0.0.0.0/tcp/" + toString(portGateway)
outputFile := logPath + "/ipfs.log"
err = NewCommand().
Run("ipfs shutdown || echo \"supress an error\"").
Run("rm -rf ~/.ipfs").
Run("ipfs init").
Run("ipfs bootstrap rm --all").
Run("ipfs config Addresses.API %s", addressAPI).
Run("ipfs config Addresses.Gateway %s", addressGateway).
Output(outputFile).
RunAsync("ipfs daemon").
CheckOutput(
"Daemon is ready",
"server listening on "+addressAPI,
"server listening on "+addressGateway).
Err()
return
}
func snetIsConfiguredLocalRpc(table *godog.Table) (err error) {
fmt.Println("snetIsConfiguredLocalRpc")
rpc_port := getTableValue(table, "Ethereum RPC port")
user_name := getTableValue(table, "user name")
ipfs_port := getTableValue(table, "IPFS port")
err = NewCommand().
Run("rm -rf ~/.snet").
Run("snet network create local http://localhost:%s", rpc_port).
Run("snet identity create %s rpc --network local", user_name).
Run("snet set default_ipfs_endpoint http://localhost:%s", ipfs_port).
Run("snet set current_singularitynettoken_at " + singnetTokenAddress).
Run("snet set current_registry_at " + registryAddress).
Run("snet set current_multipartyescrow_at " + multiPartyEscrow).
Err()
return
}
func organizationIsAdded(table *godog.Table) (err error) {
organization := getTableValue(table, "organization")
etcd_endpoint := getTableValue(table, "etcd endpoint")
group_name := getTableValue(table, "group name")
org_type := getTableValue(table, "type")
//snet organization add-group group1 0x42A605c07EdE0E1f648aB054775D6D4E38496144 5.5.6.7:8089
err = NewCommand().
Run("snet organization metadata-init %s %s %s", organization, organization, org_type).
Run("snet organization add-group %s `snet account print --wallet-index 1` %s ", group_name, etcd_endpoint).
Run("snet organization create %s -y", organization).
Err()
return
}
func getTableValue(table *godog.Table, column string) string {
names := table.Rows[0].Cells
for i, cell := range names {
if cell.Value == column {
return table.Rows[1].Cells[i].Value
}
}
log.Printf("column: %s has not been found in table", column)
return ""
}