|
1 | 1 | #![cfg(feature = "test-sbf")]
|
2 | 2 | #![feature(type_changing_struct_update)]
|
3 | 3 |
|
4 |
| -use example_native_token_transfers::error::NTTError; |
| 4 | +use example_native_token_transfers::{config::Config, error::NTTError}; |
5 | 5 | use ntt_messages::mode::Mode;
|
6 | 6 | use solana_program_test::*;
|
7 | 7 | use solana_sdk::{instruction::InstructionError, signer::Signer, transaction::TransactionError};
|
8 | 8 |
|
9 | 9 | use crate::{
|
10 |
| - common::{setup::setup, submit::Submittable}, |
11 |
| - sdk::instructions::admin::{set_threshold, SetThreshold}, |
| 10 | + common::{ |
| 11 | + query::GetAccountDataAnchor, |
| 12 | + setup::{setup, TestData}, |
| 13 | + submit::Submittable, |
| 14 | + }, |
| 15 | + sdk::instructions::admin::{ |
| 16 | + deregister_transceiver, register_transceiver, set_threshold, DeregisterTransceiver, |
| 17 | + RegisterTransceiver, SetThreshold, |
| 18 | + }, |
12 | 19 | };
|
13 | 20 |
|
14 | 21 | pub mod common;
|
15 | 22 | pub mod sdk;
|
16 | 23 |
|
| 24 | +async fn assert_threshold( |
| 25 | + ctx: &mut ProgramTestContext, |
| 26 | + test_data: &TestData, |
| 27 | + expected_threshold: u8, |
| 28 | +) { |
| 29 | + let config_account: Config = ctx.get_account_data_anchor(test_data.ntt.config()).await; |
| 30 | + assert_eq!(config_account.threshold, expected_threshold); |
| 31 | +} |
| 32 | + |
| 33 | +#[tokio::test] |
| 34 | +async fn test_reregister_all_transceivers() { |
| 35 | + let (mut ctx, test_data) = setup(Mode::Locking).await; |
| 36 | + |
| 37 | + // register ntt_transceiver |
| 38 | + register_transceiver( |
| 39 | + &test_data.ntt, |
| 40 | + RegisterTransceiver { |
| 41 | + payer: ctx.payer.pubkey(), |
| 42 | + owner: test_data.program_owner.pubkey(), |
| 43 | + transceiver: ntt_transceiver::ID, |
| 44 | + }, |
| 45 | + ) |
| 46 | + .submit_with_signers(&[&test_data.program_owner], &mut ctx) |
| 47 | + .await |
| 48 | + .unwrap(); |
| 49 | + |
| 50 | + // set threshold to 2 |
| 51 | + set_threshold( |
| 52 | + &test_data.ntt, |
| 53 | + SetThreshold { |
| 54 | + owner: test_data.program_owner.pubkey(), |
| 55 | + }, |
| 56 | + 2, |
| 57 | + ) |
| 58 | + .submit_with_signers(&[&test_data.program_owner], &mut ctx) |
| 59 | + .await |
| 60 | + .unwrap(); |
| 61 | + |
| 62 | + // deregister ntt_transceiver |
| 63 | + deregister_transceiver( |
| 64 | + &test_data.ntt, |
| 65 | + DeregisterTransceiver { |
| 66 | + owner: test_data.program_owner.pubkey(), |
| 67 | + transceiver: ntt_transceiver::ID, |
| 68 | + }, |
| 69 | + ) |
| 70 | + .submit_with_signers(&[&test_data.program_owner], &mut ctx) |
| 71 | + .await |
| 72 | + .unwrap(); |
| 73 | + assert_threshold(&mut ctx, &test_data, 1).await; |
| 74 | + |
| 75 | + // deregister baked-in transceiver |
| 76 | + deregister_transceiver( |
| 77 | + &test_data.ntt, |
| 78 | + DeregisterTransceiver { |
| 79 | + owner: test_data.program_owner.pubkey(), |
| 80 | + transceiver: example_native_token_transfers::ID, |
| 81 | + }, |
| 82 | + ) |
| 83 | + .submit_with_signers(&[&test_data.program_owner], &mut ctx) |
| 84 | + .await |
| 85 | + .unwrap(); |
| 86 | + assert_threshold(&mut ctx, &test_data, 1).await; |
| 87 | + |
| 88 | + // reregister ntt_transceiver |
| 89 | + register_transceiver( |
| 90 | + &test_data.ntt, |
| 91 | + RegisterTransceiver { |
| 92 | + payer: ctx.payer.pubkey(), |
| 93 | + owner: test_data.program_owner.pubkey(), |
| 94 | + transceiver: ntt_transceiver::ID, |
| 95 | + }, |
| 96 | + ) |
| 97 | + .submit_with_signers(&[&test_data.program_owner], &mut ctx) |
| 98 | + .await |
| 99 | + .unwrap(); |
| 100 | + assert_threshold(&mut ctx, &test_data, 1).await; |
| 101 | + |
| 102 | + // reregister baked-in transceiver |
| 103 | + register_transceiver( |
| 104 | + &test_data.ntt, |
| 105 | + RegisterTransceiver { |
| 106 | + payer: ctx.payer.pubkey(), |
| 107 | + owner: test_data.program_owner.pubkey(), |
| 108 | + transceiver: example_native_token_transfers::ID, |
| 109 | + }, |
| 110 | + ) |
| 111 | + .submit_with_signers(&[&test_data.program_owner], &mut ctx) |
| 112 | + .await |
| 113 | + .unwrap(); |
| 114 | + assert_threshold(&mut ctx, &test_data, 1).await; |
| 115 | +} |
| 116 | + |
17 | 117 | #[tokio::test]
|
18 | 118 | async fn test_zero_threshold() {
|
19 | 119 | let (mut ctx, test_data) = setup(Mode::Locking).await;
|
|
0 commit comments