Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch committed May 6, 2020
1 parent 26f30a9 commit 89c0456
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
13 changes: 6 additions & 7 deletions proc-macro/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,8 @@ impl Step {
.unwrap();

#(
assert_eq!(
result.find_event::<#event_name<_>>().unwrap(),
Some(#event)
);
let event = result.find_event::<#event_name<_>>().unwrap().unwrap();
assert_eq!(event, #event);
)*

#post
Expand Down Expand Up @@ -502,13 +500,14 @@ mod tests {
.await
.unwrap();

let event = result.find_event::<TransferEvent<_>>().unwrap().unwrap();
assert_eq!(
result.find_event::<TransferEvent<_>>().unwrap(),
Some(TransferEvent {
event,
TransferEvent {
from: alice.clone(),
to: bob.clone(),
amount: 10_000,
})
}
);

let post = {
Expand Down
4 changes: 0 additions & 4 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ impl<T: System> TryFrom<Metadata> for EventsDecoder<T> {
type_sizes: HashMap::new(),
marker: PhantomData,
};
// REMOVE when https://github.com/paritytech/substrate-subxt/pull/102 is merged
// Balance type will be registered by the proc macro.
decoder.register_type_size::<u128>("Balance")?;

// register default event arg type sizes for dynamic decoding of events
decoder.register_type_size::<bool>("bool")?;
decoder.register_type_size::<u32>("ReferendumIndex")?;
Expand Down
28 changes: 15 additions & 13 deletions src/frame/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@ pub struct TotalIssuanceStore<T: Balances> {
pub _runtime: PhantomData<T>,
}

/// The account info.
#[derive(Clone, Debug, Eq, PartialEq, Store, Encode)]
pub struct AccountStore<'a, T: Balances> {
#[store(returns = AccountData<T::Balance>)]
/// Account id to fetch info for.
pub account_id: &'a <T as System>::AccountId,
}

/// Transfer some liquid free balance to another account.
///
/// `transfer` will set the `FreeBalance` of the sender and receiver.
Expand Down Expand Up @@ -117,7 +109,13 @@ pub struct TransferEvent<T: Balances> {
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::test_client;
use crate::{
system::{
AccountStore,
AccountStoreExt,
},
tests::test_client,
};
use sp_keyring::AccountKeyring;

subxt_test!({
Expand All @@ -137,24 +135,28 @@ mod tests {
amount: 10_000,
},
assert: {
assert_eq!(pre.alice.free, post.alice.free - 10_000);
assert_eq!(pre.bob.free, post.bob.free + 10_000);
assert!(pre.alice.data.free - 10_000 >= post.alice.data.free);
assert_eq!(pre.bob.data.free, post.bob.data.free + 10_000);
},
},
});

#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_state_total_issuance() {
env_logger::try_init().ok();
let client = test_client().await;
client.total_issuance().await.unwrap().unwrap();
let total_issuance = client.total_issuance().await.unwrap().unwrap();
assert_ne!(total_issuance, 0);
}

#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_state_read_free_balance() {
env_logger::try_init().ok();
let client = test_client().await;
let account = AccountKeyring::Alice.to_account_id();
client.account(&account).await.unwrap().unwrap();
let info = client.account(&account).await.unwrap().unwrap();
assert_ne!(info.data.free, 0);
}
}
12 changes: 8 additions & 4 deletions src/frame/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ mod tests {
)
"#;
let wasm = wabt::wat2wasm(CONTRACT).expect("invalid wabt");
let code_hash = [0u8; 32].into();
let contract = bob.clone();
let mut buf = [0u8; 32];
hex::decode_to_slice(
"4d8b39b728b35fee98001095400a61f5c2ef91e0c807b1f1754b17f0397360ba",
&mut buf,
).unwrap();
let code_hash = buf.into();
},
step: {
call: PutCodeCall {
Expand All @@ -144,13 +148,13 @@ mod tests {
step: {
call: InstantiateCall {
endowment: 100_000_000_000_000,
gas_limit: 500_000,
gas_limit: 500_000_000,
code_hash: &code_hash,
data: &[],
},
event: InstantiatedEvent {
caller: alice.clone(),
contract,
contract: event.contract.clone(),
},
},
});
Expand Down

0 comments on commit 89c0456

Please sign in to comment.