mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 12:14:21 +01:00
* update UnrollClosure * update TrustedOnboarding flow + add TrustedOnboarding e2e test * fix linter: grpc.Dial * add comment * integration tests: faucet the ASP with 2 utxos
118 lines
2.4 KiB
Go
118 lines
2.4 KiB
Go
package e2e
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os/exec"
|
|
"strings"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
password = "password"
|
|
)
|
|
|
|
type arkBalance struct {
|
|
Offchain struct {
|
|
Total int `json:"total"`
|
|
} `json:"offchain_balance"`
|
|
Onchain struct {
|
|
Spendable int `json:"spendable_amount"`
|
|
Locked []struct {
|
|
Amount int `json:"amount"`
|
|
SpendableAt string `json:"spendable_at"`
|
|
} `json:"locked_amount"`
|
|
} `json:"onchain_balance"`
|
|
}
|
|
|
|
type arkReceive struct {
|
|
Offchain string `json:"offchain_address"`
|
|
Onchain string `json:"onchain_address"`
|
|
}
|
|
|
|
type arkTrustedOnboard struct {
|
|
OnboardAddress string `json:"onboard_address"`
|
|
}
|
|
|
|
func runOceanCommand(arg ...string) (string, error) {
|
|
args := append([]string{"exec", "oceand", "ocean"}, arg...)
|
|
return runCommand("docker", args...)
|
|
}
|
|
|
|
func runArkCommand(arg ...string) (string, error) {
|
|
args := append([]string{"exec", "-t", "arkd", "ark"}, arg...)
|
|
return runCommand("docker", args...)
|
|
}
|
|
|
|
func generateBlock() error {
|
|
if _, err := runCommand("nigiri", "rpc", "--liquid", "generatetoaddress", "1", "el1qqwk722tghgkgmh3r2ph4d2apwj0dy9xnzlenzklx8jg3z299fpaw56trre9gpk6wmw0u4qycajqeva3t7lzp7wnacvwxha59r"); err != nil {
|
|
return err
|
|
}
|
|
|
|
time.Sleep(6 * time.Second)
|
|
return nil
|
|
}
|
|
|
|
func runCommand(name string, arg ...string) (string, error) {
|
|
errb := new(strings.Builder)
|
|
cmd := newCommand(name, arg...)
|
|
|
|
stdout, err := cmd.StdoutPipe()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
stderr, err := cmd.StderrPipe()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
return "", err
|
|
}
|
|
output := new(strings.Builder)
|
|
errorb := new(strings.Builder)
|
|
|
|
var wg sync.WaitGroup
|
|
wg.Add(2)
|
|
|
|
go func() {
|
|
defer wg.Done()
|
|
if _, err := io.Copy(output, stdout); err != nil {
|
|
fmt.Fprintf(errb, "error reading stdout: %s", err)
|
|
}
|
|
}()
|
|
|
|
go func() {
|
|
defer wg.Done()
|
|
if _, err := io.Copy(errorb, stderr); err != nil {
|
|
fmt.Fprintf(errb, "error reading stderr: %s", err)
|
|
}
|
|
}()
|
|
|
|
wg.Wait()
|
|
if err := cmd.Wait(); err != nil {
|
|
if errMsg := errorb.String(); len(errMsg) > 0 {
|
|
return "", fmt.Errorf(errMsg)
|
|
}
|
|
|
|
if outMsg := output.String(); len(outMsg) > 0 {
|
|
return "", fmt.Errorf(outMsg)
|
|
}
|
|
|
|
return "", err
|
|
}
|
|
|
|
if errMsg := errb.String(); len(errMsg) > 0 {
|
|
return "", fmt.Errorf(errMsg)
|
|
}
|
|
|
|
return strings.Trim(output.String(), "\n"), nil
|
|
}
|
|
|
|
func newCommand(name string, arg ...string) *exec.Cmd {
|
|
cmd := exec.Command(name, arg...)
|
|
return cmd
|
|
}
|