Skip to content

Commit

Permalink
changes to integration test workflow plus new integration tests (usin…
Browse files Browse the repository at this point in the history
…g flextesa) (#350)

* sg-flextesa remove use of build tag to filter unit test run

* sg-flextesa remove the tests being replaced

* sg-flextesa add new integration tests

* sg-flextesa missed a file - removing build tag filter from unit tests

* sg-flextesa add new tests

* sg-flextesa attempt to get workflow to trigger

* sg-flextesa attempt to get workflow to trigger

* sg-flextesa move integration test workflow into build and test workflow

* sg-flextesa add docker login step to integration tests job

* sg-flextesa correct path

* sg-flextesa add debug, remove log.Fatal

* sg-flextesa add more debug

* sg-flextesa problems writing files - add a hacky chown to octez container

* sg-flextesa wrestle file permissions in octez container

* sg-flextesa add env var to kill step

* sg-flextesa make integration test job depend on publish job. refactor an env var

* Update operationkinds_test.go

fix typo in comment
  • Loading branch information
stephengaudet authored May 5, 2023
1 parent 29ce81a commit fb32a2c
Show file tree
Hide file tree
Showing 30 changed files with 596 additions and 265 deletions.
36 changes: 35 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
./cc-test-reporter before-build
echo "Running tests..."
go test -coverprofile c.out ./...
go test $(go list ./... | grep -v integration_test) -coverprofile c.out ./...
mod="$(cat go.mod | awk '/^module/ {print $2}')"
Expand Down Expand Up @@ -99,3 +99,37 @@ jobs:
- name: goreleaser release
run: make release
if: startsWith(github.ref, 'refs/tags/v')

integration-tests:
if: "!startsWith(github.ref, 'refs/tags/v')"
needs: publish
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
octez-versions:
- v16.0-rc3
env:
IMAGE: ghcr.io/ecadlabs/signatory:${{ github.head_ref || github.ref_name }}-amd64
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub
uses: docker/login-action@v2
if: "!startsWith(github.ref, 'refs/tags/v')"
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull images
run: >
docker pull oxheadalpha/flextesa:latest;
docker pull tezos/tezos:${{ matrix.octez-versions }};
docker pull $IMAGE;
- name: Start containers
run: IMAGE=$IMAGE OCTEZ_VERSION=${{ matrix.octez-versions }} docker compose -f integration_test/docker-compose.yml up -d --wait
- name: Modify octez
run: docker exec octez sudo chown -R tezos /home/tezos/.tezos-client
- name: Run tests
run: IMAGE=$IMAGE OCTEZ_VERSION=${{ matrix.octez-versions }} go test $(go list ./... | grep integration_test)
- name: Kill containers
run: IMAGE=$IMAGE OCTEZ_VERSION=${{ matrix.octez-versions }} docker compose -f integration_test/docker-compose.yml kill
23 changes: 0 additions & 23 deletions .github/workflows/integration-tests.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions cmd/approve-list-svc/server/server_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !integration

package server_test

import (
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kr/text v0.2.0 // indirect
golang.org/x/exp v0.0.0-20230420155640-133eef4313cb // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20230420155640-133eef4313cb h1:rhjz/8Mbfa8xROFiH+MQphmAmgqRM0bOMnytznhWEXk=
golang.org/x/exp v0.0.0-20230420155640-133eef4313cb/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
Expand Down
2 changes: 2 additions & 0 deletions integration_test/.tezos-client/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{ "base_dir": "/home/tezos/.tezos-client",
"endpoint": "http://flextesa:20000", "web_port": 8080, "confirmations": 0 }
4 changes: 4 additions & 0 deletions integration_test/.tezos-client/public_key_hashs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ { "name": "alice", "value": "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" },
{ "name": "bob", "value": "tz1aSkwEot3L2kmUvcoxzjMomb9mvBNuzFK6" },
{ "name": "opstest", "value": "tz1RKGhRF4TZNCXEfwyqZshGsVfrZeVU446B" },
{ "name": "opstest1", "value": "tz1R8HJMzVdZ9RqLCknxeq9w5rSbiqJ41szi" } ]
20 changes: 20 additions & 0 deletions integration_test/.tezos-client/public_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[ { "name": "alice",
"value":
{ "locator":
"http://signatory:6732/tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
"key": "edpkvGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhjn" } },
{ "name": "bob",
"value":
{ "locator":
"http://signatory:6732/tz1aSkwEot3L2kmUvcoxzjMomb9mvBNuzFK6",
"key": "edpkurPsQ8eUApnLUJ9ZPDvu98E8VNj4KtJa1aZr16Cr5ow5VHKnz4" } },
{ "name": "opstest",
"value":
{ "locator":
"http://signatory:6732/tz1RKGhRF4TZNCXEfwyqZshGsVfrZeVU446B",
"key": "edpkvSkEEfVMKvAv87env4kMNwLfuLYe7y7wXqgfvrwJwhJJpmL1GB" } },
{ "name": "opstest1",
"value":
{ "locator":
"http://signatory:6732/tz1R8HJMzVdZ9RqLCknxeq9w5rSbiqJ41szi",
"key": "edpktfLxRbpLeFjL49Rz2xtBwPaSfdZ7ZL6W3idm2JaMTP93RwmCdo" } } ]
8 changes: 8 additions & 0 deletions integration_test/.tezos-client/secret_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[ { "name": "alice",
"value": "http://signatory:6732/tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" },
{ "name": "bob",
"value": "http://signatory:6732/tz1aSkwEot3L2kmUvcoxzjMomb9mvBNuzFK6" },
{ "name": "opstest",
"value": "http://signatory:6732/tz1RKGhRF4TZNCXEfwyqZshGsVfrZeVU446B" },
{ "name": "opstest1",
"value": "http://signatory:6732/tz1R8HJMzVdZ9RqLCknxeq9w5rSbiqJ41szi" } ]
23 changes: 0 additions & 23 deletions integration_test/Dockerfile

This file was deleted.

32 changes: 32 additions & 0 deletions integration_test/authorizedkeys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package integrationtest

import (
"log"
"testing"

"github.com/stretchr/testify/require"
)

func TestAuthorizedKeys(t *testing.T) {
var c Config
c.Read("signatory.yaml")
c.Server.Keys = []string{"edpkujLb5ZCZ2gprnRzE9aVHKZfx9A8EtWu2xxkwYSjBUJbesJ9rWE"}
backup_then_update_config(c)
defer restore_config()
restart_signatory()

out, err := OctezClient("-w", "1", "transfer", "1", "from", "alice", "to", "bob")
require.NotNil(t, err)
require.Contains(t, string(out), "remote signer expects authentication signature, but no authorized key was found in the wallet")

out, err = OctezClient("import", "secret", "key", "auth", "unencrypted:edsk3ZAm9nqEo7qNugo2wcmxWnbDe7oUUmHt5UJYDdqwucsaHTAsVQ", "--force")
defer OctezClient("forget", "address", "auth", "--force")
if err != nil {
log.Println("failed to import auth key: " + err.Error() + string(out))
}
require.Nil(t, err)

out, err = OctezClient("-w", "1", "transfer", "1", "from", "alice", "to", "bob")
require.Nil(t, err)
require.Contains(t, string(out), "Operation successfully injected in the node.")
}
60 changes: 60 additions & 0 deletions integration_test/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package integrationtest

import (
"log"
"os"

yaml "gopkg.in/yaml.v3"
)

type Config struct {
Server ServerConfig `yaml:"server"`
Vaults map[string]*VaultConfig `yaml:"vaults"`
Tezos TezosConfig `yaml:"tezos"`
}

type ServerConfig struct {
Address string `yaml:"address"`
UtilityAddress string `yaml:"utility_address"`
Keys []string `yaml:"authorized_keys,omitempty"`
}

type TezosConfig = map[string]*TezosPolicy

type TezosPolicy struct {
Allow map[string][]string `yaml:"allow"`
LogPayloads bool `yaml:"log_payloads"`
}

type VaultConfig struct {
Driver string `yaml:"driver"`
Conf map[string]*string `yaml:"config"`
}

type FileVault struct {
File string `yaml:"file"`
}

func (c *Config) Read(file string) error {
yamlFile, err := os.ReadFile(file)
if err != nil {
return err
}
if err = yaml.Unmarshal(yamlFile, c); err != nil {
return err
}

return nil
}

func (c *Config) Write(file string) error {
yamlFile, err := yaml.Marshal(c)
if err != nil {
log.Fatal(err)
}
if err = os.WriteFile(file, yamlFile, 0644); err != nil {
log.Fatal(err)
}

return nil
}
16 changes: 16 additions & 0 deletions integration_test/contract.event.tz
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ parameter unit ;
storage unit ;
code { DROP ;
UNIT ;
PUSH nat 10 ;
LEFT string ;
EMIT %event ;
PUSH string "lorem ipsum" ;
RIGHT nat ;
EMIT %event (or (nat %number) (string %words)) ;
NIL operation ;
SWAP ;
CONS ;
SWAP ;
CONS ;
PAIR } }
72 changes: 72 additions & 0 deletions integration_test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
version: "3.9"
networks:
ecadnet: {}
services:

flextesa:
container_name: flextesa
image: oxheadalpha/flextesa:latest
ports:
- "20000:20000"
- "20001:20001"
networks:
- ecadnet
volumes:
- ./flextesa.sh:/usr/bin/sigybox
environment:
- block_time=3
command: sigybox
healthcheck:
test: "curl --fail http://localhost:20000/chains/main/blocks/head/header || exit 1"
interval: 1s
timeout: 1s
retries: 10
start_period: 1s

octez:
container_name: octez
image: tezos/tezos:$OCTEZ_VERSION
networks:
- ecadnet
entrypoint: tail -f /dev/null
volumes:
- ./.tezos-client:/home/tezos/.tezos-client
- ./contract.event.tz:/home/tezos/contract.event.tz
depends_on:
flextesa:
condition: service_healthy
signatory:
condition: service_healthy
healthcheck:
test: ["CMD", "octez-client", "list", "known", "addresses"]
interval: 1s
timeout: 1s
retries: 10
start_period: 1s

signatory:
container_name: signatory
image: $IMAGE
ports:
- "6732:6732"
- "9583:9583"
networks:
- ecadnet
configs:
- source: sigy-config
target: /etc/signatory.yaml
- source: sigy-secret
target: /etc/secret.json
command: serve
healthcheck:
test: "curl --fail http://localhost:6732/authorized_keys || exit 1"
interval: 1s
timeout: 1s
retries: 10
start_period: 1s

configs:
sigy-config:
file: ./signatory.yaml
sigy-secret:
file: ./signatory-local-secret.json
30 changes: 30 additions & 0 deletions integration_test/flextesa.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#! /bin/sh

protocol=Mumbai
time_bb=${block_time:-1}


export alice="$(flextesa key alice)"
export bob="$(flextesa key bob)"
export speculos="speculos,edpktsKqhvR7kXbRWD7yDgLSD7PZUXvjLqf9SFscXhL52pUStF5nQp,tz1RVYaHiobUKXMfJ47F7Rjxx5tu3LC35WSA,unencrypted:edskRuZGqmXodGDghUhpHV5mfcmfEpA46FLs5kY6QBbyzpfb9JQEwpvrumBroTJ9iyHcY8PKdRAusCLPf7vDRVXhfN8WHE5r8m"
export b0="$(flextesa key bootacc-0)"
export user1="user1,edpkvNSVE2pL4eaCYrew1NEuLi4nnYmwQfe4tdM4NoVgNMEoVCNGoW,tz1QgHGuotVTCmYtA2Mr83FdiWLbwKqUvdnp,unencrypted:edsk3bNBh8s1eovydiRv6YitZHQpBkcS9s9ATQHRZfUQxUKcFU9Mh7"

root_path=/tmp/mini-box

flextesa mini-net \
--root "$root_path" --size 1 "$@" \
--set-history-mode N000:archive \
--number-of-b 1 \
--balance-of-bootstrap-accounts tez:100_000_000 \
--time-b "$time_bb" \
--add-bootstrap-account="$alice@2_000_000_000_000" \
--add-bootstrap-account="$speculos@2_000_000_000_000" \
--add-bootstrap-account="$bob@2_000_000_000_000" \
--add-bootstrap-account="$user1@2_000_000_000_000" \
--no-daemons-for=alice \
--no-daemons-for=bob \
--no-daemons-for=speculos \
--no-daemons-for=user1 \
--until-level 200_000_000 \
--protocol-kind "$protocol"
Loading

0 comments on commit fb32a2c

Please sign in to comment.