async fn run_actions(nns_rt: &Runtime, app_rt: &Runtime, actions: &[Action]) {
    for (owner, mess) in actions {
        let ledger = Canister::new(nns_rt, LEDGER_CANISTER_ID);
        match mess {
            Message::InitialAccountQuery(want_to_see) => {
                let princ: PrincipalId = match owner {
                    Ok(princ) => *princ,
                    Err(keypair) => ed25519_public_to_principal(&keypair.public.to_bytes()),
                };
                let balance: Tokens = ledger
                    .query_(
                        "account_balance",
                        candid_one,
                        BinaryAccountBalanceArgs {
                            account: AccountIdentifier::new(princ, None).to_address(),
                        },
                    )
                    .await
                    .unwrap();
                assert_eq!(*want_to_see, balance);
            }
            Message::Send((from_funds, to_funds), to, amount) => {
                let to_account = AccountIdentifier::new(*to, None);
                let debit = (*amount + TRANSACTION_FEE).unwrap();
                let block: Option<(BlockHeight, AccountIdentifier, Memo)> = match owner {
                    Ok(princ) => {
                        let rt = if *princ == LIFELINE_CANISTER_ID.get() {
                            nns_rt
                        } else {
                            app_rt
                        };
                        let from_account = AccountIdentifier::new(*princ, None);
                        Canister::new(rt, CanisterId::new(*princ).unwrap())
                            .update_(
                                "check_and_send",
                                candid::<Option<u64>, _>,
                                (
                                    from_account.to_address(),
                                    from_funds,
                                    to_account.to_address(),
                                    to_funds,
                                    *amount,
                                ),
                            )
                            .await
                            .unwrap()
                            .map(|tip| (tip, from_account, Memo(42)))
                    }
                    Err(keypair) => {
                        let args = TransferArgs {
                            memo: Memo::default(),
                            from_subaccount: None,
                            amount: *amount,
                            fee: TRANSACTION_FEE,
                            to: to_account.to_address(),
                            created_at_time: None,
                        };
                        let result: Result<Result<BlockHeight, TransferError>, String> = ledger
                            .update_from_sender(
                                "transfer",
                                candid_one,
                                args,
                                &Sender::from_keypair(keypair),
                            )
                            .await;
                        if debit <= *from_funds {
                            let from_princ =
                                ed25519_public_to_principal(&keypair.public.to_bytes());
                            Some((
                                result.unwrap().unwrap(),
                                AccountIdentifier::new(from_princ, None),
                                Memo::default(),
                            ))
                        } else {
                            assert!(
                                matches!(result, Ok(Err(TransferError::InsufficientFunds { .. }))),
                                "unexpected result: {:?}",
                                result
                            );
                            Option::None
                        }
                    }
                };

                if let Some((tip, from_account, memo)) = block {
                    let trans = obtain_block(&ledger, tip).await;
                    assert_eq!(trans.memo, memo);
                    if let Operation::Transfer {
                        from,
                        to,
                        amount: amnt,
                        fee,
                    } = trans.operation
                    {
                        assert_eq!(from, from_account);
                        assert_eq!(to, to_account);
                        assert_eq!(amnt, *amount);
                        assert_eq!(fee, TRANSACTION_FEE);
                    } else {
                        panic!("Encountered {:?}", trans.operation)
                    }
                }
            }
        }
    }
}
/// `run_actions` performs all the IC communication corresponding to the
/// sequence of actions. Checks results.
`run_actions` performs all the IC communication corresponding to the
sequence of actions. Checks results.
` run_actions ` performs all the IC communication corresponding to the sequence of actions . Checks results .
async fn run_actions(nns_rt: &Runtime, app_rt: &Runtime, actions: &[Action]) {
    for (owner, mess) in actions {
        let ledger = Canister::new(nns_rt, LEDGER_CANISTER_ID);
        match mess {
            Message::InitialAccountQuery(want_to_see) => {
                let princ: PrincipalId = match owner {
                    Ok(princ) => *princ,
                    Err(keypair) => ed25519_public_to_principal(&keypair.public.to_bytes()),
                };
                let balance: Tokens = ledger
                    .query_(
                        "account_balance",
                        candid_one,
                        BinaryAccountBalanceArgs {
                            account: AccountIdentifier::new(princ, None).to_address(),
                        },
                    )
                    .await
                    .unwrap();
                assert_eq!(*want_to_see, balance);
            }
            Message::Send((from_funds, to_funds), to, amount) => {
                let to_account = AccountIdentifier::new(*to, None);
                let debit = (*amount + TRANSACTION_FEE).unwrap();
                let block: Option<(BlockHeight, AccountIdentifier, Memo)> = match owner {
                    Ok(princ) => {
                        let rt = if *princ == LIFELINE_CANISTER_ID.get() {
                            nns_rt
                        } else {
                            app_rt
                        };
                        let from_account = AccountIdentifier::new(*princ, None);
                        Canister::new(rt, CanisterId::new(*princ).unwrap())
                            .update_(
                                "check_and_send",
                                candid::<Option<u64>, _>,
                                (
                                    from_account.to_address(),
                                    from_funds,
                                    to_account.to_address(),
                                    to_funds,
                                    *amount,
                                ),
                            )
                            .await
                            .unwrap()
                            .map(|tip| (tip, from_account, Memo(42)))
                    }
                    Err(keypair) => {
                        let args = TransferArgs {
                            memo: Memo::default(),
                            from_subaccount: None,
                            amount: *amount,
                            fee: TRANSACTION_FEE,
                            to: to_account.to_address(),
                            created_at_time: None,
                        };
                        let result: Result<Result<BlockHeight, TransferError>, String> = ledger
                            .update_from_sender(
                                "transfer",
                                candid_one,
                                args,
                                &Sender::from_keypair(keypair),
                            )
                            .await;
                        if debit <= *from_funds {
                            let from_princ =
                                ed25519_public_to_principal(&keypair.public.to_bytes());
                            Some((
                                result.unwrap().unwrap(),
                                AccountIdentifier::new(from_princ, None),
                                Memo::default(),
                            ))
                        } else {
                            assert!(
                                matches!(result, Ok(Err(TransferError::InsufficientFunds { .. }))),
                                "unexpected result: {:?}",
                                result
                            );
                            Option::None
                        }
                    }
                };
                if let Some((tip, from_account, memo)) = block {
                    let trans = obtain_block(&ledger, tip).await;
                    assert_eq!(trans.memo, memo);
                    if let Operation::Transfer {
                        from,
                        to,
                        amount: amnt,
                        fee,
                    } = trans.operation
                    {
                        assert_eq!(from, from_account);
                        assert_eq!(to, to_account);
                        assert_eq!(amnt, *amount);
                        assert_eq!(fee, TRANSACTION_FEE);
                    } else {
                        panic!("Encountered {:?}", trans.operation)
                    }
                }
            }
        }
    }
}
async fn run_actions ( nns_rt : & Runtime , app_rt : & Runtime , actions : & [ Action ] ) { for ( owner , mess ) in actions { let ledger = Canister :: new ( nns_rt , LEDGER_CANISTER_ID ) ; match mess { Message :: InitialAccountQuery ( want_to_see ) => { let princ : PrincipalId = match owner { Ok ( princ ) => * princ , Err ( keypair ) => ed25519_public_to_principal ( & keypair . public . to_bytes ( ) ) , } ; let balance : Tokens = ledger . query_ ( " " , candid_one , BinaryAccountBalanceArgs { account : AccountIdentifier :: new ( princ , None ) . to_address ( ) , } , ) . await . unwrap ( ) ; assert_eq ! ( want_to_see balance ) ; } Message :: Send ( ( from_funds , to_funds ) , to , amount ) => { let to_account = AccountIdentifier :: new ( * to , None ) ; let debit = ( * amount + TRANSACTION_FEE ) . unwrap ( ) ; let block : Option < ( BlockHeight , AccountIdentifier , Memo ) > = match owner { Ok ( princ ) => { let rt = if * princ == LIFELINE_CANISTER_ID . get ( ) { nns_rt } else { app_rt } ; let from_account = AccountIdentifier :: new ( * princ , None ) ; Canister :: new ( rt , CanisterId :: new ( * princ ) . unwrap ( ) ) . update_ ( " " , candid :: < Option < u64 > , _ > , ( from_account . to_address ( ) , from_funds , to_account . to_address ( ) , to_funds , * amount , ) , ) . await . unwrap ( ) . map ( | tip | ( tip , from_account , Memo ( 42 ) ) ) } Err ( keypair ) => { let args = TransferArgs { memo : Memo :: default ( ) , from_subaccount : None , amount : * amount , fee : TRANSACTION_FEE , to : to_account . to_address ( ) , created_at_time : None , } ; let result : Result < Result < BlockHeight , TransferError > , String > = ledger . update_from_sender ( " " , candid_one , args , & Sender :: from_keypair ( keypair ) , ) . await ; if debit <= * from_funds { let from_princ = ed25519_public_to_principal ( & keypair . public . to_bytes ( ) ) ; Some ( ( result . unwrap ( ) . unwrap ( ) , AccountIdentifier :: new ( from_princ , None ) , Memo :: default ( ) , ) ) } else { assert ! ( matches ( result Ok ( Err ( TransferError InsufficientFunds { } ) ) ) " " result ) ; Option :: None } } } ; if let Some ( ( tip , from_account , memo ) ) = block { let trans = obtain_block ( & ledger , tip ) . await ; assert_eq ! ( trans memo memo ) ; if let Operation :: Transfer { from , to , amount : amnt , fee , } = trans . operation { assert_eq ! ( from from_account ) ; assert_eq ! ( to to_account ) ; assert_eq ! ( amnt amount ) ; assert_eq ! ( fee TRANSACTION_FEE ) ; } else { panic ! ( " " trans operation ) } } } } } }
`run_actions` performs all the IC communication corresponding to the
sequence of actions.
` run_actions ` performs all the IC communication corresponding to the sequence of actions .
nns_rt
&Runtime
app_rt
&Runtime
actions
&[Action]
nns_rt
&Runtime
app_rt
&Runtime
actions
&[Action]