-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathaptos.go
More file actions
169 lines (153 loc) · 4.74 KB
/
aptos.go
File metadata and controls
169 lines (153 loc) · 4.74 KB
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
package blockchain
import (
"context"
"fmt"
"path/filepath"
"runtime"
"strings"
"github.com/docker/docker/api/types/container"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/pods"
)
const (
DefaultAptosAPIPort = "8080"
DefaultAptosFaucetPort = "8081"
DefaultAptosArm64Image = "ghcr.io/friedemannf/aptos-tools:aptos-node-v1.41.5"
DefaultAptosX86_64Image = "aptoslabs/tools:aptos-node-v1.41.5"
)
var (
DefaultAptosAccount = "0xa337b42bd0eecf8fb59ee5929ea4541904b3c35a642040223f3d26ab57f59d6e"
DefaultAptosPrivateKey = "0xd477c65f88ed9e6d4ec6e2014755c3cfa3e0c44e521d0111a02868c5f04c41d4"
)
func defaultAptos(in *Input) {
if in.Image == "" {
// Aptos doesn't support an official arm64 image yet, so we use a custom image for now
// CI Runners use x86_64 images, so CI checks will use the official image
if runtime.GOARCH == "arm64" {
// Uses an unofficial image built for arm64
framework.L.Warn().Msgf("Using unofficial Aptos image for arm64 %s", DefaultAptosArm64Image)
in.Image = DefaultAptosArm64Image
} else {
// Official Aptos image
in.Image = DefaultAptosX86_64Image
}
}
framework.L.Warn().Msgf("Aptos node API can only be exposed on port %s!", DefaultAptosAPIPort)
if in.Port == "" {
// enable default API exposed port
in.Port = DefaultAptosAPIPort
}
if in.CustomPorts == nil {
// enable default API and faucet forwarding
in.CustomPorts = append(in.CustomPorts, fmt.Sprintf("%s:%s", in.Port, DefaultAptosAPIPort), fmt.Sprintf("%s:%s", DefaultAptosFaucetPort, DefaultAptosFaucetPort))
}
}
func newAptos(ctx context.Context, in *Input) (*Output, error) {
defaultAptos(in)
containerName := framework.DefaultTCName("blockchain-node")
absPath, err := filepath.Abs(in.ContractsDir)
if err != nil {
return nil, err
}
exposedPorts, bindings, err := framework.GenerateCustomPortsData(in.CustomPorts)
if err != nil {
return nil, err
}
exposedPorts = append(exposedPorts, in.Port)
cmd := []string{
"aptos",
"node",
"run-local-testnet",
"--with-faucet",
"--force-restart",
"--bind-to",
"0.0.0.0",
}
if len(in.DockerCmdParamsOverrides) > 0 {
cmd = append(cmd, in.DockerCmdParamsOverrides...)
}
// Set image platform based on architecture
var imagePlatform string
if runtime.GOARCH == "arm64" {
imagePlatform = "linux/arm64"
} else {
imagePlatform = "linux/amd64"
}
if pods.K8sEnabled() {
return nil, fmt.Errorf("K8s support is not yet implemented")
}
req := testcontainers.ContainerRequest{
Image: in.Image,
ExposedPorts: exposedPorts,
WaitingFor: wait.ForLog("Faucet is ready"),
Name: containerName,
Labels: framework.DefaultTCLabels(),
Networks: []string{framework.DefaultNetworkName},
NetworkAliases: map[string][]string{
framework.DefaultNetworkName: {containerName},
},
HostConfigModifier: func(h *container.HostConfig) {
h.PortBindings = bindings
framework.ResourceLimitsFunc(h, in.ContainerResources)
},
ImagePlatform: imagePlatform,
Cmd: cmd,
Files: []testcontainers.ContainerFile{
{
HostFilePath: absPath,
ContainerFilePath: "/",
},
},
}
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
if err != nil {
return nil, err
}
host, err := c.Host(ctx)
if err != nil {
return nil, err
}
dc, err := framework.NewDockerClient()
if err != nil {
return nil, err
}
cmdStr := []string{"aptos", "init", "--network=local", "--assume-yes", fmt.Sprintf("--private-key=%s", DefaultAptosPrivateKey)}
_, err = dc.ExecContainerWithContext(ctx, containerName, cmdStr)
if err != nil {
return nil, err
}
fundCmd := []string{"aptos", "account", "fund-with-faucet", "--account", DefaultAptosAccount, "--amount", "1000000000000"}
_, err = dc.ExecContainerWithContext(ctx, containerName, fundCmd)
if err != nil {
return nil, err
}
// expose default API port if remapped
var exposedAPIPort string
for _, portPair := range in.CustomPorts {
if strings.Contains(portPair, fmt.Sprintf(":%s", DefaultAptosAPIPort)) {
exposedAPIPort = strings.Split(portPair, ":")[0]
}
}
return &Output{
UseCache: true,
Type: in.Type,
Family: FamilyAptos,
ContainerName: containerName,
NetworkSpecificData: &NetworkSpecificData{
AptosNetwork: &AptosNetworkInfo{
FaucetURL: fmt.Sprintf("http://%s:%s", host, DefaultAptosFaucetPort),
},
},
Nodes: []*Node{
{
ExternalHTTPUrl: fmt.Sprintf("http://%s:%s", host, exposedAPIPort),
InternalHTTPUrl: fmt.Sprintf("http://%s:%s", containerName, in.Port),
},
},
}, nil
}