-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aptos network support
- Loading branch information
Showing
17 changed files
with
356 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Aptos Blockchain Client | ||
|
||
You need to turn `Rosetta` off to use this image! Image doesn't work with `OrbStack` currently. | ||
|
||
Docker Desktop | ||
|
||
![img.png](rosetta-settings.png) | ||
|
||
Default image is `aptoslabs/tools:aptos-node-v1.18.0` | ||
|
||
API is available on [localhost:8080](http://localhost:8080/v1) | ||
|
||
## Configuration | ||
|
||
```toml | ||
[blockchain_a] | ||
type = "aptos" | ||
image = "aptoslabs/tools:aptos-node-v1.18.0" # or aptoslabs/tools:nightly | ||
contracts_dir = "$your_dir" | ||
``` | ||
|
||
## Usage | ||
|
||
```golang | ||
package examples | ||
|
||
import ( | ||
"github.com/go-resty/resty/v2" | ||
"github.com/smartcontractkit/chainlink-testing-framework/framework" | ||
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
type CfgAptos struct { | ||
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"` | ||
} | ||
|
||
func TestAptosSmoke(t *testing.T) { | ||
in, err := framework.Load[CfgAptos](t) | ||
require.NoError(t, err) | ||
|
||
bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA) | ||
require.NoError(t, err) | ||
|
||
// execute any additional commands, to deploy contracts or set up | ||
// network is already funded, here are the keys | ||
_ = blockchain.DefaultAptosAccount | ||
_ = blockchain.DefaultAptosPrivateKey | ||
|
||
_, err = framework.ExecContainer(bc.ContainerName, []string{"ls", "-lah"}) | ||
require.NoError(t, err) | ||
|
||
t.Run("test something", func(t *testing.T) { | ||
// use internal URL to connect Chainlink nodes | ||
_ = bc.Nodes[0].DockerInternalHTTPUrl | ||
// use host URL to interact | ||
_ = bc.Nodes[0].HostHTTPUrl | ||
r := resty.New().SetBaseURL(bc.Nodes[0].HostHTTPUrl).EnableTrace() | ||
_, err := r.R().Get("/v1/transactions") | ||
require.NoError(t, err) | ||
}) | ||
} | ||
``` | ||
|
||
## Test Private Keys | ||
|
||
Default account is already funded with `100000000 Octas` | ||
|
||
``` | ||
Account: 0xa337b42bd0eecf8fb59ee5929ea4541904b3c35a642040223f3d26ab57f59d6e | ||
PrivateKey: 0xd477c65f88ed9e6d4ec6e2014755c3cfa3e0c44e521d0111a02868c5f04c41d4 | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Add Aptos network support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package blockchain | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/docker/docker/api/types/container" | ||
"github.com/smartcontractkit/chainlink-testing-framework/framework" | ||
"github.com/testcontainers/testcontainers-go" | ||
"github.com/testcontainers/testcontainers-go/wait" | ||
"path/filepath" | ||
) | ||
|
||
var ( | ||
DefaultAptosAccount = "0xa337b42bd0eecf8fb59ee5929ea4541904b3c35a642040223f3d26ab57f59d6e" | ||
DefaultAptosPrivateKey = "0xd477c65f88ed9e6d4ec6e2014755c3cfa3e0c44e521d0111a02868c5f04c41d4" | ||
) | ||
|
||
func defaultAptos(in *Input) { | ||
if in.Image == "" { | ||
in.Image = "aptoslabs/tools:aptos-node-v1.18.0" | ||
} | ||
if in.Port != "" { | ||
framework.L.Warn().Msg("'port' field is set but only default port can be used: 8080") | ||
} | ||
in.Port = "8080" | ||
} | ||
|
||
func newAptos(in *Input) (*Output, error) { | ||
defaultAptos(in) | ||
ctx := context.Background() | ||
containerName := framework.DefaultTCName("blockchain-node") | ||
|
||
absPath, err := filepath.Abs(in.ContractsDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
bindPort := fmt.Sprintf("%s/tcp", in.Port) | ||
|
||
req := testcontainers.ContainerRequest{ | ||
Image: in.Image, | ||
ExposedPorts: []string{in.Port}, | ||
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 = framework.MapTheSamePort(bindPort) | ||
}, | ||
ImagePlatform: "linux/amd64", | ||
Cmd: []string{ | ||
"aptos", | ||
"node", | ||
"run-local-testnet", | ||
"--with-faucet", | ||
"--force-restart", | ||
"--bind-to", | ||
"0.0.0.0", | ||
}, | ||
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 | ||
} | ||
cmdStr := []string{"aptos", "init", "--network=local", "--assume-yes", fmt.Sprintf("--private-key=%s", DefaultAptosPrivateKey)} | ||
_, err = framework.ExecContainer(containerName, cmdStr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
fundCmd := []string{"aptos", "account", "fund-with-faucet", "--account", DefaultAptosAccount} | ||
_, err = framework.ExecContainer(containerName, fundCmd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &Output{ | ||
UseCache: true, | ||
Family: "aptos", | ||
ContainerName: containerName, | ||
Nodes: []*Node{ | ||
{ | ||
HostHTTPUrl: fmt.Sprintf("http://%s:%s", host, in.Port), | ||
DockerInternalHTTPUrl: fmt.Sprintf("http://%s:%s", containerName, in.Port), | ||
}, | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.