test_flag_node.rs
1 // use core::panic; 2 // 3 // use anchor_client::{ 4 // anchor_lang::{ 5 // prelude::{AccountMeta, System}, 6 // system_program, Id, 7 // }, 8 // solana_client::rpc_client::RpcClient, 9 // solana_sdk::{ 10 // self, 11 // commitment_config::CommitmentConfig, 12 // pubkey::Pubkey, 13 // signature::{read_keypair_file, Keypair}, 14 // signer::Signer, 15 // system_instruction, 16 // transaction::Transaction, 17 // }, 18 // Client, Cluster, 19 // }; 20 // 21 // use crate::create_account; 22 // 23 // #[test] 24 // fn test_flag_node() { 25 // let program_id = akinnet::id(); 26 // let anchor_wallet = std::env::var("ANCHOR_WALLET").unwrap(); 27 // let payer = read_keypair_file(&anchor_wallet).unwrap(); 28 // 29 // let client = Client::new_with_options(Cluster::Localnet, &payer, CommitmentConfig::confirmed()); 30 // let program = client.program(program_id).unwrap(); 31 // let rpc = program.rpc(); 32 // 33 // let user1 = create_account(&payer, &rpc, 5000000000); 34 // eprintln!("user1: {}", user1.pubkey()); 35 // let user2 = create_account(&payer, &rpc, 50000000); 36 // eprintln!("user2: {}", user2.pubkey()); 37 // 38 // let (root_entry, _) = 39 // Pubkey::find_program_address(&[b"root", user1.pubkey().as_ref()], &program_id); 40 // eprintln!("root: {}", root_entry); 41 // 42 // let (me_entry, _) = 43 // Pubkey::find_program_address(&[b"persona", b"me", user1.pubkey().as_ref()], &program_id); 44 // eprintln!("me: {}", me_entry); 45 // 46 // program 47 // .request() 48 // .accounts(akinnet::accounts::Initialize { 49 // root_entry, 50 // owner: user1.pubkey(), 51 // self_persona_entry: me_entry, 52 // system_program: System::id(), 53 // }) 54 // .args(akinnet::instruction::Initialize { 55 // name: "me".to_string(), 56 // description: "Akinnet".to_string(), 57 // }) 58 // .signer(&user1) 59 // .send() 60 // .expect(""); 61 // 62 // let (question_entry, _) = Pubkey::find_program_address( 63 // &[b"question", b"alive", user2.pubkey().as_ref()], 64 // &program_id, 65 // ); 66 // let (persona_entry, _) = Pubkey::find_program_address( 67 // &[b"persona", b"Jason Statham", user2.pubkey().as_ref()], 68 // &program_id, 69 // ); 70 // 71 // program 72 // .request() 73 // .accounts(akinnet::accounts::SuggestPersona { 74 // persona_entry, 75 // question_entry, 76 // prev_node_entry: root_entry.clone(), 77 // wrong_persona_entry: me_entry, 78 // owner: user2.pubkey(), 79 // system_program: System::id(), 80 // }) 81 // .args(akinnet::instruction::SuggestPersona { 82 // name: "Jason Statham".to_string(), 83 // description: "A good guy".to_string(), 84 // question: "alive".to_string(), 85 // wrong_is_yes: false, 86 // }) 87 // .signer(&user2) 88 // .send() 89 // .expect(""); 90 // 91 // program 92 // .request() 93 // .accounts(akinnet::accounts::FlagNode { 94 // to_flag: persona_entry, 95 // flagger: user2.pubkey(), 96 // system_program: System::id(), 97 // }) 98 // .args(akinnet::instruction::FlagNode {}) 99 // .signer(&user2) 100 // .send() 101 // .expect(""); 102 // 103 // program 104 // .request() 105 // .accounts(akinnet::accounts::FlagNode { 106 // to_flag: persona_entry, 107 // flagger: user1.pubkey(), 108 // system_program: System::id(), 109 // }) 110 // .accounts(vec![AccountMeta { 111 // pubkey: user2.pubkey(), 112 // is_signer: false, 113 // is_writable: true, 114 // }]) 115 // .args(akinnet::instruction::FlagNode {}) 116 // .signer(&user1) 117 // .send() 118 // .expect(""); 119 // 120 // let flagged_node: akinnet::state::NodeState = program.account(persona_entry).unwrap(); 121 // assert_eq!( 122 // flagged_node.flagged_by, 123 // vec![user2.pubkey(), user1.pubkey()] 124 // ); 125 // assert_eq!(rpc.get_balance(&persona_entry).unwrap(), 0); 126 // assert_eq!(rpc.get_balance(&user1.pubkey()).unwrap(), 0); 127 // assert_eq!(rpc.get_balance(&user2.pubkey()).unwrap(), 0); 128 // }