Files
serai/substrate/serai/client/tests/burn.rs

80 lines
2.4 KiB
Rust
Raw Normal View History

Tokens pallet (#243) * Use Monero-compatible additional TX keys This still sends a fingerprinting flare up if you send to a subaddress which needs to be fixed. Despite that, Monero no should no longer fail to scan TXs from monero-serai regarding additional keys. Previously it failed becuase we supplied one key as THE key, and n-1 as additional. Monero expects n for additional. This does correctly select when to use THE key versus when to use the additional key when sending. That removes the ability for recipients to fingerprint monero-serai by receiving to a standard address yet needing to use an additional key. * Add tokens_primitives Moves OutInstruction from in-instructions. Turns Destination into OutInstruction. * Correct in-instructions DispatchClass * Add initial tokens pallet * Don't allow pallet addresses to equal identity * Add support for InInstruction::transfer Requires a cargo update due to modifications made to serai-dex/substrate. Successfully mints a token to a SeraiAddress. * Bind InInstructions to an amount * Add a call filter to the runtime Prevents worrying about calls to the assets pallet/generally tightens things up. * Restore Destination It was meged into OutInstruction, yet it didn't make sense for OutInstruction to contain a SeraiAddress. Also deletes the excessively dated Scenarios doc. * Split PublicKey/SeraiAddress Lets us define a custom Display/ToString for SeraiAddress. Also resolves an oddity where PublicKey would be encoded as String, not [u8; 32]. * Test burning tokens/retrieving OutInstructions Modularizes processor_coinUpdates into a shared testing utility. * Misc lint * Don't use PolkadotExtrinsicParams
2023-01-28 01:47:13 -05:00
use core::time::Duration;
use rand_core::{RngCore, OsRng};
use sp_core::Pair;
use serai_runtime::in_instructions::{Batch, Update};
use tokio::time::sleep;
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner};
use serai_client::{
primitives::{
BITCOIN, BlockNumber, BlockHash, SeraiAddress, Amount, WithAmount, Balance, Data,
ExternalAddress, insecure_pair_from_name,
},
in_instructions::primitives::InInstruction,
tokens::{primitives::OutInstruction, TokensEvent},
Serai,
};
mod runner;
use runner::{URL, provide_updates};
serai_test!(
async fn burn() {
let coin = BITCOIN;
let mut id = BlockHash([0; 32]);
OsRng.fill_bytes(&mut id.0);
let block_number = BlockNumber(u32::try_from(OsRng.next_u64() >> 32).unwrap());
let pair = insecure_pair_from_name("Alice");
let public = pair.public();
let address = SeraiAddress::from(public);
let amount = Amount(OsRng.next_u64());
let balance = Balance { coin, amount };
let mut rand_bytes = vec![0; 32];
OsRng.fill_bytes(&mut rand_bytes);
let external_address = ExternalAddress::new(rand_bytes).unwrap();
let mut rand_bytes = vec![0; 32];
OsRng.fill_bytes(&mut rand_bytes);
let data = Data::new(rand_bytes).unwrap();
let batch = Batch {
id,
instructions: vec![WithAmount { data: InInstruction::Transfer(address), amount }],
};
let update = Update { block_number, batches: vec![batch] };
let block = provide_updates(vec![Some(update)]).await;
let serai = Serai::new(URL).await.unwrap();
assert_eq!(serai.get_token_balance(block, coin, address).await.unwrap(), amount);
let out = OutInstruction { address: external_address, data: Some(data) };
let burn = Serai::burn(balance, out.clone());
let signer = PairSigner::new(pair);
serai
.publish(&serai.sign(&signer, &burn, 0, BaseExtrinsicParamsBuilder::new()).unwrap())
.await
.unwrap();
loop {
let block = serai.get_latest_block_hash().await.unwrap();
let events = serai.get_burn_events(block).await.unwrap();
if events.is_empty() {
sleep(Duration::from_millis(50)).await;
continue;
}
assert_eq!(events, vec![TokensEvent::Burn { address, balance, instruction: out }]);
assert_eq!(serai.get_token_supply(block, coin).await.unwrap(), Amount(0));
assert_eq!(serai.get_token_balance(block, coin, address).await.unwrap(), Amount(0));
break;
}
}
);