Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add e2e test for simple_dex
  • Loading branch information
obrok committed Nov 9, 2022
commit ca84acf8cd3cbd157a593d063486f941a2ecb3d4
36 changes: 35 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,37 @@ 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> {
match &value.0 {
Value::Tuple(tuple) => 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 @@ -98,15 +98,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 @@ -123,15 +123,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 @@ -166,7 +166,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" \
--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 @@ -12,7 +12,7 @@ use crate::{
fee_calculation as test_fee_calculation, finalization as test_finalization,
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,
staking_era_payouts as test_staking_era_payouts,
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,
treasury_access as test_treasury_access, validators_rotate as test_validators_rotate,
Expand Down Expand Up @@ -63,5 +63,6 @@ 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),
]
}
8 changes: 8 additions & 0 deletions e2e-tests/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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 @@ -95,4 +99,8 @@ pub struct TestCaseParams {
/// Path to the marketplace metadata file. Only used by button tests.
#[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>,
}
Loading