#!/bin/bash

set -e

source $SRCROOT/integration/common

trap exit_handler EXIT

heading 'Setup...'

echo 'logging in..'
# we do this at run-time instead of build time
# to eliminate the risk of copying over a stale adamoracle binary
# if we had instead copied over the binary from the built adamoracle
# base image
# we could also try mounting a volume instead, or using docker-exec
echo 'copy binary'
docker cp adamoracle-node:/usr/local/bin/adamoracle /usr/local/bin/adamoracle
  waitForResponse $ADAMORACLE_URL
  title "Adamoracle is running."
echo 'adamoracle admin login'
adamoracle admin login --file /run/secrets/apicredentials
echo 'launch_adamoracle'
launch_adamoracle
echo 'deploy_contracts'
deploy_contracts

heading 'Running tests...'
cd $SRCROOT/integration

./runlog_test
./ethlog_test
deploy_v05_contracts

title 'End to end tests.'

yarn workspace adamoracle-contracts_v1/integration test:cypress
title 'All tests passed.'
