mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 20:54:20 +01:00
Add integration tests and regtest support (#128)
* regtest support + integration tests (e2e) * add integration CI * add PR trigger on integration CI * wait for ocean to be unlocked at startup * integration tests: add tests flags and build docker images at startup * use nigiri chopsticks-liquid * fix after reviews * Update client/init.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> Signed-off-by: Louis Singer <41042567+louisinger@users.noreply.github.com> * do not trigger integration on PR --------- Signed-off-by: Louis Singer <41042567+louisinger@users.noreply.github.com> Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
This commit is contained in:
109
server/test/e2e/utils.go
Normal file
109
server/test/e2e/utils.go
Normal file
@@ -0,0 +1,109 @@
|
||||
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"`
|
||||
}
|
||||
|
||||
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()
|
||||
io.Copy(output, stdout)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
io.Copy(errorb, stderr)
|
||||
}()
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user