Skip to content

Commit

Permalink
Fix CI config to run e2e tests correctly #69
Browse files Browse the repository at this point in the history
This is a 55-commit squash, mostly debug messages. Steps along the way include:
- update Dockerfile to pull the correct branch
- make sure the blockchain level is appropriate
- add dynamic configuration of sandbox URI
- separate tests into a configurable Dockerfile, put original image on ghcr
- use correct version of pytezos
- optimize performance by setting up sandbox before building
  • Loading branch information
marsella committed Mar 14, 2022
1 parent 0a6e5eb commit 51ffdf8
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 39 deletions.
50 changes: 28 additions & 22 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,47 @@ jobs:
id: tags
run: |
TAG=$(echo $GITHUB_SHA | head -c7)
IMAGE="dev/test"
IMAGE="zeekoe_base"
echo ::set-output name=tagged_image::${IMAGE}:${TAG}
echo ::set-output name=tag::${TAG}
- uses: docker/setup-buildx-action@v1
id: buildx

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run sandbox
run: |
docker run --rm --name sandbox --detach -p 20000:20000 tqtezos/flextesa:20210602 flobox start
echo "SANDBOX_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' sandbox)" >> $GITHUB_ENV
- name: Build
id: docker_build
uses: docker/build-push-action@v2
with:
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: false
load: true
context: .
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
tags: ${{ steps.tags.outputs.tagged_image }}

- name: Run sandbox
run: docker run --rm --name my-sandbox --detach -p 20000:20000 tqtezos/flextesa:20210602 flobox start
# this will only be set for pull request runs. otherwise it will default to main
build-args: BRANCH=${{ github.head_ref }}
tags: ghcr.io/${{ github.repository_owner }}/${{ steps.tags.outputs.tagged_image }}

- name: Configure tezos client and run all test targets
uses: addnab/docker-run-action@v3
- name: Run tests (configure tezos client, run integration tests)
uses: docker/build-push-action@v2
with:
image: ${{ steps.tags.outputs.tagged_image }}
docker_network: host
run: |
tezos-client config reset
tezos-client --endpoint http://localhost:20000 bootstrapped
tezos-client --endpoint http://localhost:20000 config update
tezos-client import secret key alice unencrypted:edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSpJiEbq
tezos-client import secret key bob unencrypted:edsk3RFfvaFaxbHx8BMtEW1rKQcPtDML3LXjNqMNLCzC3wLC1bWbAt
cargo test --all-features --all-targets --verbose
file: ./integration_tests/Dockerfile
context: .
builder: ${{ steps.buildx.outputs.name }}
pull: true
load: true
build-args: |
zeekoe_base=ghcr.io/${{ github.repository_owner }}/${{ steps.tags.outputs.tagged_image }}
tezos_uri=http://${{ env.SANDBOX_IP }}:20000
- name: Move cache
run: |
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Rust
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ RUN apt-get update
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

RUN pip3 install pytezos
RUN pip3 install pytezos==3.2.11

# Define the branch here to prevent caching old versions of the repository
ARG BRANCH=main
RUN git clone https://github.com/boltlabs-inc/zeekoe.git
WORKDIR /root/zeekoe

RUN git checkout $BRANCH
RUN git submodule update --init --recursive
RUN ./dev/generate-certificates; CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --features "allow_explicit_certificate_trust allow_custom_self_delay"

Expand Down
11 changes: 11 additions & 0 deletions integration_tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ARG zeekoe_base
FROM ${zeekoe_base}

ARG tezos_uri
RUN tezos-client config reset
RUN tezos-client --endpoint ${tezos_uri} bootstrapped
RUN tezos-client --endpoint ${tezos_uri} config update
RUN tezos-client import secret key alice unencrypted:edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSpJiEbq
RUN tezos-client import secret key bob unencrypted:edsk3RFfvaFaxbHx8BMtEW1rKQcPtDML3LXjNqMNLCzC3wLC1bWbAt

RUN cargo test --all-features --tests integration_tests --verbose -- ${tezos_uri}
32 changes: 19 additions & 13 deletions integration_tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ pub const ERROR_FILENAME: &str = "integration_tests/gen/errors.log";
#[derive(Debug, Clone, Copy, EnumIter)]
enum MerchantServices {
IpV4,
IpV6,
//IpV6,
}

impl MerchantServices {
fn to_str(self) -> &'static str {
match self {
Self::IpV4 => "127.0.0.1",
Self::IpV6 => "::1",
//Self::IpV6 => "::1",
}
}
}
Expand All @@ -49,7 +49,7 @@ impl fmt::Display for MerchantServices {
// Note: this hard-codes the default port.
let ipaddr = match self {
Self::IpV4 => self.to_str().to_string(),
Self::IpV6 => format!("[{}]", self.to_str()),
//Self::IpV6 => format!("[{}]", self.to_str()),
};
write!(f, "{}:2611", ipaddr)
}
Expand Down Expand Up @@ -106,7 +106,7 @@ macro_rules! merchant_cli {
}
pub(crate) use merchant_cli;

pub async fn setup(rng: &StdRng) -> ServerFuture {
pub async fn setup(rng: &StdRng, tezos_uri: String) -> ServerFuture {
let _ = fs::create_dir("integration_tests/gen");

// Create self-signed SSL certificate in the generated directory
Expand All @@ -116,8 +116,8 @@ pub async fn setup(rng: &StdRng) -> ServerFuture {
.expect("Failed to generate new certificates");

// write config options for each party
let customer_config = customer_test_config().await;
let merchant_config = merchant_test_config().await;
let customer_config = customer_test_config(&tezos_uri).await;
let merchant_config = merchant_test_config(&tezos_uri).await;

// set up tracing for all log messages
tracing_subscriber::fmt()
Expand Down Expand Up @@ -148,10 +148,12 @@ pub async fn setup(rng: &StdRng) -> ServerFuture {
Party::MerchantServer,
TestLogs::MerchantServerSpawned(MerchantServices::IpV4.to_string()),
),
/*
await_log(
Party::MerchantServer,
TestLogs::MerchantServerSpawned(MerchantServices::IpV6.to_string()),
),
*/
await_log(Party::CustomerWatcher, TestLogs::CustomerWatcherSpawned),
];

Expand Down Expand Up @@ -187,14 +189,15 @@ pub async fn teardown(server_future: ServerFuture) {
}

/// Encode the customizable fields of the zeekoe customer Config struct for testing.
async fn customer_test_config() -> zeekoe::customer::Config {
async fn customer_test_config(tezos_uri: &str) -> zeekoe::customer::Config {
let quoted_tezos_uri = format!("\"{}\"", tezos_uri);
let m = HashMap::from([
("database", "{ sqlite = \"customer.db\" }"),
("trust_certificate", "\"localhost.crt\""),
("tezos_account", "{ alias = \"alice\" }"),
("tezos_uri", "\"http://localhost:20000\""),
("tezos_uri", quoted_tezos_uri.as_str()),
("self_delay", "120"),
("confirmation_depth", "1"),
("confirmation_depth", "2"),
]);

let contents = m.into_iter().fold("".to_string(), |acc, (key, value)| {
Expand All @@ -209,13 +212,14 @@ async fn customer_test_config() -> zeekoe::customer::Config {
}

/// Encode the customizable fields of the zeekoe merchant Config struct for testing.
async fn merchant_test_config() -> zeekoe::merchant::Config {
async fn merchant_test_config(tezos_uri: &str) -> zeekoe::merchant::Config {
let quoted_tezos_uri = format!("\"{}\"", tezos_uri);
let m = HashMap::from([
("database", "{ sqlite = \"merchant.db\" }"),
("tezos_account", "{ alias = \"bob\" }"),
("tezos_uri", "\"http://localhost:20000\""),
("tezos_uri", quoted_tezos_uri.as_str()),
("self_delay", "120"),
("confirmation_depth", "1"),
("confirmation_depth", "2"),
]);

let tezos_contents = m.into_iter().fold("".to_string(), |acc, (key, value)| {
Expand Down Expand Up @@ -273,8 +277,10 @@ struct BlockchainLevelDetail {
}

/// The minimum required depth to originate contracts on the Tezos blockchain.
static MINIMUM_LEVEL: u64 = 120;
static MINIMUM_LEVEL: u64 = 60;

/// Waits for the blockchain level to reach the required minimum depth. Necessary when using the
/// sandbox, which will start at 0 by default.
pub async fn await_leveled_blockchain(
config: &zeekoe::customer::Config,
) -> Result<(), anyhow::Error> {
Expand Down
12 changes: 11 additions & 1 deletion integration_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@ use {

#[tokio::main]
pub async fn main() {
// Read tezos URI from arguments, or use standard sandbox URI
let default = "http://localhost:20000".to_string();
let tezos_uri = match std::env::args().last() {
None => default,
// This means no argument was passed and args just has the executable name
Some(s) if s.contains("integration_tests") => default,
Some(tezos_uri) => tezos_uri,
};
eprintln!("parsed tezos uri: {}", tezos_uri);

let rng = StdRng::from_entropy();
let server_future = common::setup(&rng).await;
let server_future = common::setup(&rng, tezos_uri).await;
let customer_config = customer::Config::load(common::CUSTOMER_CONFIG)
.await
.expect("Failed to load customer config");
Expand Down

0 comments on commit 51ffdf8

Please sign in to comment.