Merge faaae97939
into 852fcc77be
This commit is contained in:
commit
8fc443a977
|
@ -0,0 +1,2 @@
|
|||
Cargo.lock
|
||||
test-validator.log
|
|
@ -17,6 +17,7 @@ basic-4 = { path = "../../examples/tutorial/basic-4/programs/basic-4", features
|
|||
composite = { path = "../../tests/composite/programs/composite", features = ["no-entrypoint"] }
|
||||
optional = { path = "../../tests/optional/programs/optional", features = ["no-entrypoint"] }
|
||||
events = { path = "../../tests/events/programs/events", features = ["no-entrypoint"] }
|
||||
relations-derivation = { path = "../../tests/relations-derivation/programs/relations-derivation", features = ["no-entrypoint"] }
|
||||
anyhow = "1.0.32"
|
||||
clap = { version = "4.2.4", features = ["derive"] }
|
||||
shellexpand = "2.1.0"
|
||||
|
|
|
@ -18,103 +18,100 @@
|
|||
|
||||
set -euox pipefail
|
||||
|
||||
main() {
|
||||
#
|
||||
# Build programs.
|
||||
#
|
||||
local composite_pid="EHthziFziNoac9LBGxEaVN47Y3uUiRoXvqAiR6oes4iU"
|
||||
local basic_2_pid="Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
|
||||
local basic_4_pid="CwrqeMj2U8tFr1Rhkgwc84tpAsqbt9pTt2a4taoTADPr"
|
||||
local events_pid="2dhGsWUzy5YKUsjZdLHLmkNpUDAXkNa9MYWsPc4Ziqzy"
|
||||
local optional_pid="FNqz6pqLAwvMSds2FYjR4nKV3moVpPNtvkfGFrqLKrgG"
|
||||
# Root directories for each project
|
||||
composite_root="../../tests/composite"
|
||||
basic_2_root="../../examples/tutorial/basic-2"
|
||||
basic_4_root="../../examples/tutorial/basic-4"
|
||||
events_root="../../tests/events"
|
||||
optional_root="../../tests/optional"
|
||||
relations_derivation_root="../../tests/relations-derivation"
|
||||
|
||||
#
|
||||
# Bootup validator.
|
||||
#
|
||||
solana-test-validator -r \
|
||||
--bpf-program $composite_pid ../../tests/composite/target/deploy/composite.so \
|
||||
--bpf-program $basic_2_pid ../../examples/tutorial/basic-2/target/deploy/basic_2.so \
|
||||
--bpf-program $basic_4_pid ../../examples/tutorial/basic-4/target/deploy/basic_4.so \
|
||||
--bpf-program $events_pid ../../tests/events/target/deploy/events.so \
|
||||
--bpf-program $optional_pid ../../tests/optional/target/deploy/optional.so \
|
||||
> test-validator.log &
|
||||
sleep 5
|
||||
|
||||
#
|
||||
# Run single threaded test.
|
||||
#
|
||||
cargo run -- \
|
||||
--composite-pid $composite_pid \
|
||||
--basic-2-pid $basic_2_pid \
|
||||
--basic-4-pid $basic_4_pid \
|
||||
--events-pid $events_pid \
|
||||
--optional-pid $optional_pid
|
||||
|
||||
#
|
||||
# Restart validator for multithreaded test
|
||||
#
|
||||
cleanup
|
||||
solana-test-validator -r \
|
||||
--bpf-program $composite_pid ../../tests/composite/target/deploy/composite.so \
|
||||
--bpf-program $basic_2_pid ../../examples/tutorial/basic-2/target/deploy/basic_2.so \
|
||||
--bpf-program $basic_4_pid ../../examples/tutorial/basic-4/target/deploy/basic_4.so \
|
||||
--bpf-program $events_pid ../../tests/events/target/deploy/events.so \
|
||||
--bpf-program $optional_pid ../../tests/optional/target/deploy/optional.so \
|
||||
> test-validator.log &
|
||||
sleep 5
|
||||
|
||||
#
|
||||
# Run multi threaded test.
|
||||
#
|
||||
cargo run -- \
|
||||
--composite-pid $composite_pid \
|
||||
--basic-2-pid $basic_2_pid \
|
||||
--basic-4-pid $basic_4_pid \
|
||||
--events-pid $events_pid \
|
||||
--optional-pid $optional_pid \
|
||||
--multithreaded
|
||||
|
||||
#
|
||||
# Restart validator for async test
|
||||
#
|
||||
cleanup
|
||||
solana-test-validator -r \
|
||||
--bpf-program $composite_pid ../../tests/composite/target/deploy/composite.so \
|
||||
--bpf-program $basic_2_pid ../../examples/tutorial/basic-2/target/deploy/basic_2.so \
|
||||
--bpf-program $basic_4_pid ../../examples/tutorial/basic-4/target/deploy/basic_4.so \
|
||||
--bpf-program $events_pid ../../tests/events/target/deploy/events.so \
|
||||
--bpf-program $optional_pid ../../tests/optional/target/deploy/optional.so \
|
||||
> test-validator.log &
|
||||
sleep 5
|
||||
|
||||
#
|
||||
# Run async test.
|
||||
#
|
||||
cargo run --features async -- \
|
||||
--composite-pid $composite_pid \
|
||||
--basic-2-pid $basic_2_pid \
|
||||
--basic-4-pid $basic_4_pid \
|
||||
--events-pid $events_pid \
|
||||
--optional-pid $optional_pid \
|
||||
--multithreaded
|
||||
# Program IDs for each project
|
||||
composite_pid="EHthziFziNoac9LBGxEaVN47Y3uUiRoXvqAiR6oes4iU"
|
||||
basic_2_pid="Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
|
||||
basic_4_pid="CwrqeMj2U8tFr1Rhkgwc84tpAsqbt9pTt2a4taoTADPr"
|
||||
events_pid="2dhGsWUzy5YKUsjZdLHLmkNpUDAXkNa9MYWsPc4Ziqzy"
|
||||
optional_pid="FNqz6pqLAwvMSds2FYjR4nKV3moVpPNtvkfGFrqLKrgG"
|
||||
relations_derivation_pid="6mogAuKLW1uiXg8Br8YwPtCTPyxKSK4YHrCcyHu6zBUY"
|
||||
|
||||
build_programs() {
|
||||
for project_root in $composite_root $basic_2_root $basic_4_root $events_root $optional_root $relations_derivation_root; do
|
||||
pushd "$project_root"
|
||||
anchor build
|
||||
popd
|
||||
done
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
pkill -P $$ || true
|
||||
wait || true
|
||||
pkill -P $$ || true
|
||||
wait || true
|
||||
rm -f test-validator.log
|
||||
}
|
||||
|
||||
start_clean_validator() {
|
||||
cleanup
|
||||
|
||||
solana-test-validator -r \
|
||||
--bpf-program $composite_pid $composite_root/target/deploy/composite.so \
|
||||
--bpf-program $basic_2_pid $basic_2_root/target/deploy/basic_2.so \
|
||||
--bpf-program $basic_4_pid $basic_4_root/target/deploy/basic_4.so \
|
||||
--bpf-program $events_pid $events_root/target/deploy/events.so \
|
||||
--bpf-program $optional_pid $optional_root/target/deploy/optional.so \
|
||||
--bpf-program $relations_derivation_pid $relations_derivation_root/target/deploy/relations_derivation.so \
|
||||
> test-validator.log &
|
||||
sleep 5
|
||||
|
||||
pushd $relations_derivation_root
|
||||
anchor idl init $relations_derivation_pid \
|
||||
--provider.cluster localnet \
|
||||
--filepath target/idl/relations_derivation.json
|
||||
popd
|
||||
}
|
||||
|
||||
run_tests() {
|
||||
local extra_cargo_flags="$1" # Flags for cargo itself
|
||||
local extra_program_flags="$2" # Flags for the test program
|
||||
|
||||
cargo run $extra_cargo_flags -- \
|
||||
--composite-pid $composite_pid \
|
||||
--basic-2-pid $basic_2_pid \
|
||||
--basic-4-pid $basic_4_pid \
|
||||
--events-pid $events_pid \
|
||||
--optional-pid $optional_pid \
|
||||
--relations-derivation-pid $relations_derivation_pid \
|
||||
$extra_program_flags
|
||||
}
|
||||
|
||||
trap_add() {
|
||||
trap_add_cmd=$1; shift || fatal "${FUNCNAME} usage error"
|
||||
for trap_add_name in "$@"; do
|
||||
trap -- "$(
|
||||
extract_trap_cmd() { printf '%s\n' "${3:-}"; }
|
||||
eval "extract_trap_cmd $(trap -p "${trap_add_name}")"
|
||||
printf '%s\n' "${trap_add_cmd}"
|
||||
)" "${trap_add_name}" \
|
||||
|| fatal "unable to add to trap ${trap_add_name}"
|
||||
done
|
||||
trap_add_cmd=$1; shift || fatal "${FUNCNAME} usage error"
|
||||
for trap_add_name in "$@";
|
||||
do
|
||||
trap -- "$(
|
||||
extract_trap_cmd() { printf '%s\n' "${3:-}"; }
|
||||
eval "extract_trap_cmd $(trap -p "${trap_add_name}")"
|
||||
printf '%s\n' "${trap_add_cmd}"
|
||||
)" "${trap_add_name}" \
|
||||
|| fatal "unable to add to trap ${trap_add_name}"
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
build_programs
|
||||
|
||||
######
|
||||
# Run single threaded tests
|
||||
start_clean_validator
|
||||
run_tests "" ""
|
||||
|
||||
######
|
||||
# Run multithreaded tests
|
||||
start_clean_validator
|
||||
run_tests "" "--multithreaded"
|
||||
|
||||
######
|
||||
# Run async tests
|
||||
start_clean_validator
|
||||
run_tests "--features async" "--multithreaded"
|
||||
}
|
||||
|
||||
declare -f -t trap_add
|
||||
|
|
|
@ -61,6 +61,7 @@ pub fn main() -> Result<()> {
|
|||
let client = Client::new_with_options(url, payer, CommitmentConfig::processed());
|
||||
events(&client, opts.events_pid)?;
|
||||
optional(&client, opts.optional_pid)?;
|
||||
relations_derivation(&client, opts.relations_derivation_pid)?;
|
||||
} else {
|
||||
// Client.
|
||||
let payer = Arc::new(payer);
|
||||
|
@ -76,6 +77,7 @@ pub fn main() -> Result<()> {
|
|||
(&basic_4, opts.basic_4_pid),
|
||||
(&events, opts.events_pid),
|
||||
(&optional, opts.optional_pid),
|
||||
(&relations_derivation, opts.relations_derivation_pid),
|
||||
];
|
||||
let mut handles = vec![];
|
||||
for (test, arg) in tests {
|
||||
|
@ -327,3 +329,73 @@ pub fn optional<C: Deref<Target = impl Signer> + Clone>(
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Runs a client for tests/relations-derivation.
|
||||
//
|
||||
// Make sure to run a localnet with the program deploy to run this example.
|
||||
pub fn relations_derivation<C: Deref<Target = impl Signer> + Clone>(
|
||||
client: &Client<C>,
|
||||
pid: Pubkey,
|
||||
) -> Result<()> {
|
||||
use relations_derivation::{accounts, instruction};
|
||||
let program = client.program(pid)?;
|
||||
|
||||
// TODO It inits the base account
|
||||
{
|
||||
let my_account = program.payer();
|
||||
let (account, _) = Pubkey::find_program_address(&[b"seed"], &pid);
|
||||
let system_program = system_program::ID;
|
||||
|
||||
program
|
||||
.request()
|
||||
.accounts(accounts::InitBase {
|
||||
my_account,
|
||||
account,
|
||||
system_program,
|
||||
})
|
||||
.args(instruction::InitBase {})
|
||||
.send()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// TODO It derives relations
|
||||
{
|
||||
let my_account = program.payer();
|
||||
let (account, _) = Pubkey::find_program_address(&[b"seed"], &pid);
|
||||
|
||||
program
|
||||
.request()
|
||||
.accounts(accounts::TestRelation {
|
||||
my_account,
|
||||
account,
|
||||
nested: accounts::Nested {
|
||||
my_account,
|
||||
account,
|
||||
},
|
||||
})
|
||||
.args(instruction::TestRelation {})
|
||||
.send()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// TODO It can use relations derivation with seed constant:
|
||||
{
|
||||
let my_account = program.payer();
|
||||
let (account, _) = Pubkey::find_program_address(&[relations_derivation::SEED], &pid);
|
||||
let system_program = system_program::ID;
|
||||
|
||||
program
|
||||
.request()
|
||||
.accounts(accounts::TestSeedConstant {
|
||||
my_account,
|
||||
account,
|
||||
system_program,
|
||||
})
|
||||
.args(instruction::TestSeedConstant {})
|
||||
.send()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
println!("Relations derivation success!");
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ pub struct Opts {
|
|||
events_pid: Pubkey,
|
||||
#[clap(long)]
|
||||
optional_pid: Pubkey,
|
||||
#[clap(long)]
|
||||
relations_derivation_pid: Pubkey,
|
||||
#[clap(long, default_value = "false")]
|
||||
multithreaded: bool,
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ pub async fn main() -> Result<()> {
|
|||
let client = Client::new_with_options(url, payer, CommitmentConfig::processed());
|
||||
events(&client, opts.events_pid).await?;
|
||||
optional(&client, opts.optional_pid).await?;
|
||||
relations_derivation(&client, opts.relations_derivation_pid).await?;
|
||||
// Success.
|
||||
Ok(())
|
||||
}
|
||||
|
@ -304,3 +305,73 @@ pub async fn optional<C: Deref<Target = impl Signer> + Clone>(
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn relations_derivation<C: Deref<Target = impl Signer> + Clone>(
|
||||
client: &Client<C>,
|
||||
pid: Pubkey,
|
||||
) -> Result<()> {
|
||||
use relations_derivation::{accounts, instruction};
|
||||
let program = client.program(pid)?;
|
||||
|
||||
// TODO It inits the base account
|
||||
{
|
||||
let my_account = program.payer();
|
||||
let (account, _) = Pubkey::find_program_address(&[b"seed"], &pid);
|
||||
let system_program = system_program::ID;
|
||||
|
||||
program
|
||||
.request()
|
||||
.accounts(accounts::InitBase {
|
||||
my_account,
|
||||
account,
|
||||
system_program,
|
||||
})
|
||||
.args(instruction::InitBase {})
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// TODO It derives relations
|
||||
{
|
||||
let my_account = program.payer();
|
||||
let (account, _) = Pubkey::find_program_address(&[b"seed"], &pid);
|
||||
|
||||
program
|
||||
.request()
|
||||
.accounts(accounts::TestRelation {
|
||||
my_account,
|
||||
account,
|
||||
nested: accounts::Nested {
|
||||
my_account,
|
||||
account,
|
||||
},
|
||||
})
|
||||
.args(instruction::TestRelation {})
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// TODO It can use relations derivation with seed constant:
|
||||
{
|
||||
let my_account = program.payer();
|
||||
let (account, _) = Pubkey::find_program_address(&[relations_derivation::SEED], &pid);
|
||||
let system_program = system_program::ID;
|
||||
|
||||
program
|
||||
.request()
|
||||
.accounts(accounts::TestSeedConstant {
|
||||
my_account,
|
||||
account,
|
||||
system_program,
|
||||
})
|
||||
.args(instruction::TestSeedConstant {})
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
println!("Relations derivation success!");
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ cluster = "localnet"
|
|||
wallet = "~/.config/solana/id.json"
|
||||
|
||||
[programs.localnet]
|
||||
relations_derivation = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
|
||||
relations_derivation = "6mogAuKLW1uiXg8Br8YwPtCTPyxKSK4YHrCcyHu6zBUY"
|
||||
|
||||
[workspace]
|
||||
members = ["programs/relations-derivation"]
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
use anchor_lang::prelude::*;
|
||||
|
||||
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
|
||||
declare_id!("6mogAuKLW1uiXg8Br8YwPtCTPyxKSK4YHrCcyHu6zBUY");
|
||||
|
||||
pub const SEED: &[u8] = b"contant-seed";
|
||||
pub const SEED: &[u8] = b"constant-seed";
|
||||
|
||||
#[program]
|
||||
pub mod relations_derivation {
|
||||
|
|
Loading…
Reference in New Issue