|
@@ -26,7 +26,7 @@ use composite::instruction as composite_instruction;
|
|
|
use composite::{DummyA, DummyB};
|
|
|
use optional::account::{DataAccount, DataPda};
|
|
|
use std::ops::Deref;
|
|
|
-use std::rc::Rc;
|
|
|
+use std::sync::Arc;
|
|
|
use std::time::Duration;
|
|
|
use tokio::sync::mpsc;
|
|
|
use tokio::time::sleep;
|
|
@@ -43,7 +43,7 @@ pub async fn main() -> Result<()> {
|
|
|
);
|
|
|
|
|
|
// Client.
|
|
|
- let payer = Rc::new(payer);
|
|
|
+ let payer = Arc::new(payer);
|
|
|
let client =
|
|
|
Client::new_with_options(url.clone(), payer.clone(), CommitmentConfig::processed());
|
|
|
|
|
@@ -51,6 +51,7 @@ pub async fn main() -> Result<()> {
|
|
|
composite(&client, opts.composite_pid).await?;
|
|
|
basic_2(&client, opts.basic_2_pid).await?;
|
|
|
basic_4(&client, opts.basic_4_pid).await?;
|
|
|
+ test_tokio(client, opts.basic_2_pid).await?;
|
|
|
|
|
|
// Can also use references, since they deref to a signer
|
|
|
let payer: &Keypair = &payer;
|
|
@@ -61,6 +62,42 @@ pub async fn main() -> Result<()> {
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
+pub async fn test_tokio(client: Client<Arc<Keypair>>, pid: Pubkey) -> Result<()> {
|
|
|
+ tokio::spawn(async move {
|
|
|
+ let program = client.program(pid).unwrap();
|
|
|
+
|
|
|
+ // `Create` parameters.
|
|
|
+ let counter = Arc::new(Keypair::new());
|
|
|
+ let counter_pubkey = counter.pubkey();
|
|
|
+ let authority = program.payer();
|
|
|
+
|
|
|
+ // Build and send a transaction.
|
|
|
+ program
|
|
|
+ .request()
|
|
|
+ .signer(counter)
|
|
|
+ .accounts(basic_2_accounts::Create {
|
|
|
+ counter: counter_pubkey,
|
|
|
+ user: authority,
|
|
|
+ system_program: system_program::ID,
|
|
|
+ })
|
|
|
+ .args(basic_2_instruction::Create { authority })
|
|
|
+ .send()
|
|
|
+ .await
|
|
|
+ .unwrap();
|
|
|
+
|
|
|
+ let counter_account: Counter = program.account(counter_pubkey).await.unwrap();
|
|
|
+
|
|
|
+ assert_eq!(counter_account.authority, authority);
|
|
|
+ assert_eq!(counter_account.count, 0);
|
|
|
+ })
|
|
|
+ .await
|
|
|
+ .unwrap();
|
|
|
+
|
|
|
+ println!("Tokio success!");
|
|
|
+
|
|
|
+ Ok(())
|
|
|
+}
|
|
|
+
|
|
|
pub async fn composite<C: Deref<Target = impl Signer> + Clone>(
|
|
|
client: &Client<C>,
|
|
|
pid: Pubkey,
|
|
@@ -69,8 +106,8 @@ pub async fn composite<C: Deref<Target = impl Signer> + Clone>(
|
|
|
let program = client.program(pid)?;
|
|
|
|
|
|
// `Initialize` parameters.
|
|
|
- let dummy_a = Keypair::new();
|
|
|
- let dummy_b = Keypair::new();
|
|
|
+ let dummy_a = Arc::new(Keypair::new());
|
|
|
+ let dummy_b = Arc::new(Keypair::new());
|
|
|
|
|
|
// Build and send a transaction.
|
|
|
program
|
|
@@ -95,8 +132,8 @@ pub async fn composite<C: Deref<Target = impl Signer> + Clone>(
|
|
|
500,
|
|
|
&program.id(),
|
|
|
))
|
|
|
- .signer(&dummy_a)
|
|
|
- .signer(&dummy_b)
|
|
|
+ .signer(dummy_a.clone())
|
|
|
+ .signer(dummy_b.clone())
|
|
|
.accounts(Initialize {
|
|
|
dummy_a: dummy_a.pubkey(),
|
|
|
dummy_b: dummy_b.pubkey(),
|
|
@@ -147,13 +184,13 @@ pub async fn basic_2<C: Deref<Target = impl Signer> + Clone>(
|
|
|
let program = client.program(pid)?;
|
|
|
|
|
|
// `Create` parameters.
|
|
|
- let counter = Keypair::new();
|
|
|
+ let counter = Arc::new(Keypair::new());
|
|
|
let authority = program.payer();
|
|
|
|
|
|
// Build and send a transaction.
|
|
|
program
|
|
|
.request()
|
|
|
- .signer(&counter)
|
|
|
+ .signer(counter.clone())
|
|
|
.accounts(basic_2_accounts::Create {
|
|
|
counter: counter.pubkey(),
|
|
|
user: authority,
|
|
@@ -253,13 +290,13 @@ pub async fn optional<C: Deref<Target = impl Signer> + Clone>(
|
|
|
let program = client.program(pid)?;
|
|
|
|
|
|
// `Initialize` parameters.
|
|
|
- let data_account_keypair = Keypair::new();
|
|
|
+ let data_account_keypair = Arc::new(Keypair::new());
|
|
|
|
|
|
let data_account_key = data_account_keypair.pubkey();
|
|
|
|
|
|
let data_pda_seeds = &[DataPda::PREFIX.as_ref(), data_account_key.as_ref()];
|
|
|
let data_pda_key = Pubkey::find_program_address(data_pda_seeds, &pid).0;
|
|
|
- let required_keypair = Keypair::new();
|
|
|
+ let required_keypair = Arc::new(Keypair::new());
|
|
|
let value: u64 = 10;
|
|
|
|
|
|
// Build and send a transaction.
|
|
@@ -276,8 +313,8 @@ pub async fn optional<C: Deref<Target = impl Signer> + Clone>(
|
|
|
DataAccount::LEN as u64,
|
|
|
&program.id(),
|
|
|
))
|
|
|
- .signer(&data_account_keypair)
|
|
|
- .signer(&required_keypair)
|
|
|
+ .signer(data_account_keypair.clone())
|
|
|
+ .signer(required_keypair.clone())
|
|
|
.accounts(OptionalInitialize {
|
|
|
payer: Some(program.payer()),
|
|
|
required: required_keypair.pubkey(),
|