-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpublish_dnn_model_services_test.go
124 lines (100 loc) · 3.81 KB
/
publish_dnn_model_services_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
package main
import (
"fmt"
"log"
"os"
"github.com/cucumber/godog"
)
const (
configServiceName = "snetd.config.json"
)
func exampleserviceServiceIsRegistered(table *godog.Table) (err error) {
name := getTableValue(table, "name")
displayName := getTableValue(table, "display name")
daemonPort := getTableValue(table, "daemon port")
organization := getTableValue(table, "organization name")
groupname := getTableValue(table, "group name")
metadata := exampleServiceDir + "/service_metadata.json"
cmd := NewCommand().Dir(exampleServiceDir)
cmd.
Run("snet service metadata-init service/service_spec \"%s\" --encoding proto --service-type grpc --group-name %s ",
displayName, groupname).
CheckFileContains(metadata, "display_name", displayName).
CheckFileContains(metadata, "group_name", "default_group").
Run("snet service metadata-set-fixed-price %s 0.1", groupname).
CheckFileContains(metadata, "fixed_price", "price_in_cogs", "10000000").
Run("snet service metadata-add-endpoints default_group localhost:%s", daemonPort).
Run("snet service publish %s %s -y", organization, name)
return cmd.Err()
}
func exampleserviceServiceSnetdaemonConfigFileIsCreated(table *godog.Table) (err error) {
serviceName := getTableValue(table, "name")
organizationName := getTableValue(table, "organization name")
daemonPort := getTableValue(table, "daemon port")
snetdConfigTemplate := `
{
"payment_channel_storage_server": {
"enabled": true
},
"SERVICE_ID": "%s",
"ORGANIZATION_ID": "%s",
"DAEMON_END_POINT": "localhost:%s",
"ETHEREUM_JSON_RPC_ENDPOINT": "http://localhost:8545",
"PASSTHROUGH_ENABLED": true,
"PASSTHROUGH_ENDPOINT": "http://localhost:7003",
"IPFS_END_POINT": "http://localhost:5002",
"REGISTRY_ADDRESS_KEY": "%s",
"pvt_key_for_metering": "efed2ea91d5ace7f9f7bd91e21223cfded31a6e3f1a746bc52821659e0c94e17",
"metering_end_point":"http://demo8325345.mockable.io",
"log": {
"level": "debug",
"output": {
"type": "stdout"
}
}
}`
snetdConfig := fmt.Sprintf(
snetdConfigTemplate,
serviceName,
organizationName,
daemonPort,
registryAddress,
)
file := exampleServiceDir + "/" + configServiceName
log.Printf("create snetd config: %s\n---\n:%s\n---\n", file, snetdConfig)
return writeToFile(file, snetdConfig)
}
func exampleserviceServiceIsRunning() (err error) {
err = os.Chmod(exampleServiceDir+"/buildproto.sh", 0544)
if err != nil {
return
}
output := logPath + "/example-service.log"
exampleRunCmd := "python3 run_example_service.py --daemon-config " + exampleServiceDir + "/" + configServiceName
cmd := NewCommand().Dir(exampleServiceDir)
cmd.Run("rm -rf storage-data-dir-1.etcd").
Run("./buildproto.sh").
Output(output).
RunAsync(exampleRunCmd)
//CheckOutput("starting daemon") //todo this does not work well and was failing the test cases
return cmd.Err()
}
func exampleserviceMakeACallUsingPaymentChannel(table *godog.Table) (err error) {
group_name := getTableValue(table, "group name")
organization := getTableValue(table, "organization name")
service := getTableValue(table, "service name")
cmd := NewCommand().Dir(exampleServiceDir)
cmd.
Run("snet account balance").
Run("snet account deposit 42000.22 -y").
Run("snet channel open-init %s %s 42 +30days -y", organization, group_name).
Run("snet --print-traceback client call %s %s %s add '{\"a\":10,\"b\":32}' -y", organization, service, group_name)
return cmd.Err()
}
func exampleserviceClaimChannelByTreasurerServer(table *godog.Table) (err error) {
daemonPort := getTableValue(table, "daemon port")
cmd := NewCommand().Dir(exampleServiceDir)
cmd.Run("snet treasurer print-unclaimed --endpoint localhost:%s --wallet-index 1", daemonPort).
Run("snet treasurer claim-all --endpoint localhost:%s --wallet-index 1 -y", daemonPort)
return cmd.Err()
}