Tests: Transport error info on send_tx()

This commit is contained in:
Christian Kamm 2022-02-28 09:12:24 +01:00
parent 7aa2cd7e13
commit b88989bf3a
2 changed files with 16 additions and 8 deletions

View File

@ -5,6 +5,7 @@ use anchor_lang::Key;
use anchor_spl::token::{Token, TokenAccount};
use solana_sdk::instruction;
use solana_sdk::signature::{Keypair, Signer};
use solana_sdk::transport::TransportError;
#[async_trait::async_trait(?Send)]
pub trait ClientAccountLoader {
@ -23,15 +24,17 @@ impl ClientAccountLoader for &SolanaCookie {
}
// TODO: report error outwards etc
pub async fn send_tx<CI: ClientInstruction>(solana: &SolanaCookie, ix: CI) -> CI::Accounts {
pub async fn send_tx<CI: ClientInstruction>(
solana: &SolanaCookie,
ix: CI,
) -> std::result::Result<CI::Accounts, TransportError> {
let (accounts, instruction) = ix.to_instruction(solana).await;
let signers = ix.signers();
let instructions = vec![instruction];
solana
.process_transaction(&instructions, Some(&signers[..]))
.await
.unwrap();
accounts
.await?;
Ok(accounts)
}
#[async_trait::async_trait(?Send)]

View File

@ -25,11 +25,12 @@ async fn test_basic() -> Result<(), TransportError> {
let dust_threshold = 0.01;
//
// SETUP: Create a group, register a token (mint0)
// SETUP: Create a group, account, register a token (mint0)
//
let group = send_tx(solana, CreateGroupInstruction { admin, payer })
.await
.unwrap()
.group;
let account = send_tx(
@ -42,6 +43,7 @@ async fn test_basic() -> Result<(), TransportError> {
},
)
.await
.unwrap()
.account;
let register_token_accounts = send_tx(
@ -58,7 +60,8 @@ async fn test_basic() -> Result<(), TransportError> {
payer,
},
)
.await;
.await
.unwrap();
let bank = register_token_accounts.bank;
let vault = register_token_accounts.vault;
@ -79,7 +82,8 @@ async fn test_basic() -> Result<(), TransportError> {
token_authority: payer,
},
)
.await;
.await
.unwrap();
assert_eq!(solana.token_account_balance(vault).await, deposit_amount);
assert_eq!(
@ -117,7 +121,8 @@ async fn test_basic() -> Result<(), TransportError> {
banks: vec![bank],
},
)
.await;
.await
.unwrap();
assert_eq!(solana.token_account_balance(vault).await, withdraw_amount);
assert_eq!(