Skip to content

Commit

Permalink
Fixed all bouncer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
syan095 committed Nov 1, 2023
1 parent 9acde4d commit d69e3ad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
18 changes: 10 additions & 8 deletions api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,16 @@ pub trait BrokerApi: SignedExtrinsicApi {
channel_metadata: Option<CcmChannelMetadata>,
) -> Result<SwapDepositAddress> {
let (_tx_hash, events, header, ..) = self
.submit_signed_extrinsic(pallet_cf_swapping::Call::request_swap_deposit_address {
source_asset,
destination_asset,
destination_address,
broker_commission_bps,
channel_metadata,
})
.await
.submit_signed_extrinsic_with_dry_run(
pallet_cf_swapping::Call::request_swap_deposit_address {
source_asset,
destination_asset,
destination_address,
broker_commission_bps,
channel_metadata,
},
)
.await?
.until_in_block()
.await?;

Expand Down
24 changes: 12 additions & 12 deletions api/lib/src/lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ pub trait LpApi: SignedExtrinsicApi {

async fn request_liquidity_deposit_address(&self, asset: Asset) -> Result<EncodedAddress> {
let (_tx_hash, events, ..) = self
.submit_signed_extrinsic(pallet_cf_lp::Call::request_liquidity_deposit_address {
asset,
})
.await
.submit_signed_extrinsic_with_dry_run(
pallet_cf_lp::Call::request_liquidity_deposit_address { asset },
)
.await?
.until_in_block()
.await?;

Expand Down Expand Up @@ -169,15 +169,15 @@ pub trait LpApi: SignedExtrinsicApi {
) -> Result<Vec<RangeOrderReturn>> {
// Submit the mint order
let (_tx_hash, events, ..) = self
.submit_signed_extrinsic(pallet_cf_pools::Call::update_range_order {
.submit_signed_extrinsic_with_dry_run(pallet_cf_pools::Call::update_range_order {
base_asset,
pair_asset,
id,
option_tick_range,
increase_or_decrease,
size,
})
.await
.await?
.until_in_block()
.await?;

Expand All @@ -194,14 +194,14 @@ pub trait LpApi: SignedExtrinsicApi {
) -> Result<Vec<RangeOrderReturn>> {
// Submit the mint order
let (_tx_hash, events, ..) = self
.submit_signed_extrinsic(pallet_cf_pools::Call::set_range_order {
.submit_signed_extrinsic_with_dry_run(pallet_cf_pools::Call::set_range_order {
base_asset,
pair_asset,
id,
option_tick_range,
size,
})
.await
.await?
.until_in_block()
.await?;

Expand All @@ -219,15 +219,15 @@ pub trait LpApi: SignedExtrinsicApi {
) -> Result<Vec<LimitOrderReturn>> {
// Submit the mint order
let (_tx_hash, events, ..) = self
.submit_signed_extrinsic(pallet_cf_pools::Call::update_limit_order {
.submit_signed_extrinsic_with_dry_run(pallet_cf_pools::Call::update_limit_order {
sell_asset,
buy_asset,
id,
option_tick,
increase_or_decrease,
amount,
})
.await
.await?
.until_in_block()
.await?;

Expand All @@ -244,14 +244,14 @@ pub trait LpApi: SignedExtrinsicApi {
) -> Result<Vec<LimitOrderReturn>> {
// Submit the burn order
let (_tx_hash, events, ..) = self
.submit_signed_extrinsic(pallet_cf_pools::Call::set_limit_order {
.submit_signed_extrinsic_with_dry_run(pallet_cf_pools::Call::set_limit_order {
sell_asset,
buy_asset,
id,
option_tick,
sell_amount,
})
.await
.await?
.until_in_block()
.await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ pub enum DryRunError {
DryRunRpcCallError,
#[error("The reply from the dry_run RPC cannot be decoded correctly.")]
CannotDecodeReply,
#[error("The dry_run returned Invalid Transaction error.")]
TransactionInvalid,
}

pub type ExtrinsicResult<OtherError> = Result<
Expand Down Expand Up @@ -303,17 +301,16 @@ impl<'a, 'env, BaseRpcClient: base_rpc_api::BaseRpcApi + Send + Sync + 'static>
&mut self,
call: state_chain_runtime::RuntimeCall,
) -> anyhow::Result<()> {
let nonce = self.base_rpc_client.next_account_nonce(self.signer.account_id.clone()).await?;
let uxt = self.build_and_sign_extrinsic(call.clone(), nonce);
let uxt = self.build_and_sign_extrinsic(call.clone(), self.finalized_nonce);
let dry_run_result = self
.base_rpc_client
.dry_run(Encode::encode(&uxt).into(), None)
.await
.map_err(|_| ExtrinsicError::Other(DryRunError::DryRunRpcCallError))?;
let res: ApplyExtrinsicResult = Decode::decode(&mut &*dry_run_result)
.map_err(|_| ExtrinsicError::Other(DryRunError::CannotDecodeReply))?;
let res: ApplyExtrinsicResult =
Decode::decode(&mut &*dry_run_result).map_err(|_| DryRunError::CannotDecodeReply)?;
info!(target: "state_chain_client", "Dry run completed. Result: {:?}", res.clone());
res.map_err(|_| ExtrinsicError::Other(DryRunError::TransactionInvalid))?
res.map_err(|e| anyhow!("Dry run failed due to invalid transactions: {:?}", e))?
.map_err(|e| {
anyhow!(
"DispatchError during dry run: {:?}",
Expand Down

0 comments on commit d69e3ad

Please sign in to comment.