Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A0-1140: e2e tests for simple_dex #723

Merged
merged 7 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion aleph-client/src/contract/convertible_value.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::Deref;

use anyhow::{bail, Result};
use anyhow::{anyhow, bail, Result};
use contract_transcode::Value;
use sp_core::crypto::Ss58Codec;

Expand Down Expand Up @@ -71,3 +71,36 @@ impl TryFrom<ConvertibleValue> for AccountId {
}
}
}

impl<T> TryFrom<ConvertibleValue> for Result<T>
where
ConvertibleValue: TryInto<T, Error = anyhow::Error>,
{
type Error = anyhow::Error;

fn try_from(value: ConvertibleValue) -> Result<Result<T>, Self::Error> {
if let Value::Tuple(tuple) = &value.0 {
match tuple.ident() {
Some(x) if x == "Ok" => {
if tuple.values().count() == 1 {
let item =
ConvertibleValue(tuple.values().next().unwrap().clone()).try_into()?;
return Ok(Ok(item));
} else {
bail!("Unexpected number of elements in Ok variant: {:?}", &value);
}
}
Some(x) if x == "Err" => {
if tuple.values().count() == 1 {
return Ok(Err(anyhow!(value.to_string())));
} else {
bail!("Unexpected number of elements in Err variant: {:?}", &value);
}
}
_ => (),
}
}

bail!("Expected {:?} to be an Ok(_) or Err(_) tuple.", value);
}
}
14 changes: 7 additions & 7 deletions aleph-client/src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ impl ContractInstance {
conn: &C,
message: &str,
) -> Result<ConvertibleValue> {
self.contract_read(conn, message, &[])
self.contract_read::<C, String>(conn, message, &[])
}

/// Reads the value of a read-only call via RPC.
pub fn contract_read<C: AnyConnection>(
pub fn contract_read<C: AnyConnection, S: AsRef<str> + Debug>(
&self,
conn: &C,
message: &str,
args: &[&str],
args: &[S],
) -> Result<ConvertibleValue> {
let payload = self.encode(message, args)?;
let request = self.contract_read_request(&payload);
Expand All @@ -121,15 +121,15 @@ impl ContractInstance {

/// Executes a 0-argument contract call.
pub fn contract_exec0(&self, conn: &SignedConnection, message: &str) -> Result<()> {
self.contract_exec(conn, message, &[])
self.contract_exec::<String>(conn, message, &[])
}

/// Executes a contract call.
pub fn contract_exec(
pub fn contract_exec<S: AsRef<str> + Debug>(
&self,
conn: &SignedConnection,
message: &str,
args: &[&str],
args: &[S],
) -> Result<()> {
let data = self.encode(message, args)?;
let xt = compose_extrinsic!(
Expand Down Expand Up @@ -164,7 +164,7 @@ impl ContractInstance {
})
}

fn encode(&self, message: &str, args: &[&str]) -> Result<Vec<u8>> {
fn encode<S: AsRef<str> + Debug>(&self, message: &str, args: &[S]) -> Result<Vec<u8>> {
ContractMessageTranscoder::new(&self.ink_project).encode(message, args)
}

Expand Down
6 changes: 5 additions & 1 deletion contracts/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ CONTRACTS_PATH=$(pwd)/contracts
EARLY_BIRD_SPECIAL=$(jq --raw-output ".early_bird_special" < "$CONTRACTS_PATH"/addresses.json)
THE_PRESSIAH_COMETH=$(jq --raw-output ".the_pressiah_cometh" < "$CONTRACTS_PATH"/addresses.json)
BACK_TO_THE_FUTURE=$(jq --raw-output ".back_to_the_future" < "$CONTRACTS_PATH"/addresses.json)
SIMPLE_DEX=$(jq --raw-output ".simple_dex" < "$CONTRACTS_PATH"/addresses.json)

pushd "$E2E_PATH"

RUST_LOG="aleph_e2e_client=info" cargo run --release -- \
--test-cases simple_dex \
--test-cases marketplace \
--test-cases button_game_reset \
--test-cases early_bird_special \
Expand All @@ -19,9 +21,11 @@ RUST_LOG="aleph_e2e_client=info" cargo run --release -- \
--early-bird-special "$EARLY_BIRD_SPECIAL" \
--the-pressiah-cometh "$THE_PRESSIAH_COMETH" \
--back-to-the-future "$BACK_TO_THE_FUTURE" \
obrok marked this conversation as resolved.
Show resolved Hide resolved
--simple-dex "$SIMPLE_DEX" \
--button-game-metadata ../contracts/button/target/ink/metadata.json \
--ticket-token-metadata ../contracts/ticket_token/target/ink/metadata.json \
--reward-token-metadata ../contracts/game_token/target/ink/metadata.json \
--marketplace-metadata ../contracts/marketplace/target/ink/metadata.json
--marketplace-metadata ../contracts/marketplace/target/ink/metadata.json \
--simple-dex-metadata ../contracts/simple_dex/target/ink/metadata.json

exit $?
74 changes: 64 additions & 10 deletions contracts/simple_dex/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion e2e-tests/src/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
force_new_era as test_force_new_era, marketplace as test_marketplace,
points_basic as test_points_basic, points_stake_change as test_points_stake_change,
schedule_doomed_version_change_and_verify_finalization_stopped as test_schedule_doomed_version_change_and_verify_finalization_stopped,
schedule_version_change as test_schedule_version_change,
schedule_version_change as test_schedule_version_change, simple_dex as test_simple_dex,
staking_era_payouts as test_staking_era_payouts,
staking_new_validator as test_staking_new_validator,
the_pressiah_cometh as test_the_pressiah_cometh, token_transfer as test_token_transfer,
Expand Down Expand Up @@ -72,6 +72,7 @@ pub fn possible_test_cases() -> PossibleTestCases {
("back_to_the_future", test_back_to_the_future as TestCase),
("the_pressiah_cometh", test_the_pressiah_cometh as TestCase),
("marketplace", test_marketplace as TestCase),
("simple_dex", test_simple_dex as TestCase),
("ban_automatic", test_ban_automatic as TestCase),
("ban_manual", test_ban_manual as TestCase),
(
Expand Down
8 changes: 8 additions & 0 deletions e2e-tests/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ pub struct TestCaseParams {
#[clap(long)]
pub the_pressiah_cometh: Option<String>,

/// Address of the simple dex contract.
#[clap(long)]
pub simple_dex: Option<String>,

/// Path to the button game metadata file. Only used by button tests.
#[clap(long)]
pub button_game_metadata: Option<String>,
Expand All @@ -97,6 +101,10 @@ pub struct TestCaseParams {
#[clap(long)]
pub marketplace_metadata: Option<String>,

/// Path to the simple_dex metadata file. Only used by button tests.
#[clap(long)]
pub simple_dex_metadata: Option<String>,

/// Version for the VersionUpgrade test.
#[clap(long)]
pub upgrade_to_version: Option<u32>,
Expand Down
Loading