abstract-interchain-tests 0.22.2

Interchain testing library for the Abstract SDK. This is used primarily for tests but some elements are re-usable for testing apps and adapters
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
use std::str::FromStr;

use abstract_std::objects::{account::AccountTrace, chain_name::ChainName, AccountId};
// We need to rewrite this because cosmrs::Msg is not implemented for IBC types
use abstract_interface::{
    Abstract, AbstractAccount, AccountDetails, ManagerExecFns, ManagerQueryFns,
};
use anyhow::Result as AnyResult;
use cw_orch::prelude::*;
use cw_orch_interchain::prelude::*;

pub const TEST_ACCOUNT_NAME: &str = "account-test";
pub const TEST_ACCOUNT_DESCRIPTION: &str = "Description of an account";
pub const TEST_ACCOUNT_LINK: &str = "https://google.com";

pub fn set_env() {
    std::env::set_var("STATE_FILE", "daemon_state.json"); // Set in code for tests
    std::env::set_var("ARTIFACTS_DIR", "../artifacts"); // Set in code for tests
}

pub fn create_test_remote_account<Chain: IbcQueryHandler, IBC: InterchainEnv<Chain>>(
    abstr_origin: &Abstract<Chain>,
    origin_id: &str,
    remote_id: &str,
    interchain: &IBC,
    funds: Option<Vec<Coin>>,
) -> AnyResult<(AbstractAccount<Chain>, AccountId)> {
    let origin_name = ChainName::from_chain_id(origin_id).to_string();
    let remote_name = ChainName::from_chain_id(remote_id).to_string();

    // Create a local account for testing
    let account_name = TEST_ACCOUNT_NAME.to_string();
    let description = Some(TEST_ACCOUNT_DESCRIPTION.to_string());
    let link = Some(TEST_ACCOUNT_LINK.to_string());
    let origin_account = abstr_origin.account_factory.create_new_account(
        AccountDetails {
            name: account_name.clone(),
            description: description.clone(),
            link: link.clone(),
            base_asset: None,
            install_modules: vec![],
            namespace: None,
            account_id: None,
        },
        abstract_std::objects::gov_type::GovernanceDetails::Monarchy {
            monarch: abstr_origin
                .version_control
                .get_chain()
                .sender()
                .to_string(),
        },
        funds.as_deref(),
    )?;

    // We need to enable ibc on the account.
    origin_account.manager.update_settings(Some(true))?;

    // Now we send a message to the client saying that we want to create an account on the
    // destination chain
    let register_tx = origin_account.register_remote_account(&remote_name)?;

    interchain.check_ibc(origin_id, register_tx)?;

    // After this is all ended, we return the account id of the account we just created on the remote chain
    let account_config = origin_account.manager.config()?;
    let remote_account_id = AccountId::new(
        account_config.account_id.seq(),
        AccountTrace::Remote(vec![ChainName::from_str(&origin_name)?]),
    )?;

    Ok((origin_account, remote_account_id))
}

#[cfg(test)]
mod test {
    use crate::{
        setup::{ibc_abstract_setup, mock_test::logger_test_init},
        JUNO, OSMOSIS, STARGAZE,
    };

    use super::*;

    use abstract_interface::AccountFactoryExecFns;
    use abstract_std::{
        ans_host::ExecuteMsgFns as AnsExecuteMsgFns,
        ibc_client::AccountResponse,
        ibc_host::{
            ExecuteMsg as HostExecuteMsg, ExecuteMsgFns, HelperAction, HostAction, InternalAction,
        },
        manager::{
            state::AccountInfo, ConfigResponse, ExecuteMsg as ManagerExecuteMsg, InfoResponse,
        },
        objects::{gov_type::GovernanceDetails, UncheckedChannelEntry},
        ICS20, PROXY,
    };

    use abstract_interface::connection::abstract_ibc_connection_with;
    use anyhow::Result as AnyResult;
    use cosmwasm_std::{coins, to_json_binary, wasm_execute, Uint128};
    use cw_orch::mock::cw_multi_test::AppResponse;
    use cw_orch_polytone::Polytone;
    use ibc_relayer_types::core::ics24_host::identifier::PortId;
    use polytone::handshake::POLYTONE_VERSION;

    #[test]
    fn ibc_account_action() -> AnyResult<()> {
        logger_test_init();
        let mock_interchain =
            MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]);

        // We just verified all steps pass
        let (abstr_origin, abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?;

        let remote_name = ChainName::from_chain_id(STARGAZE).to_string();

        let (origin_account, remote_account_id) =
            create_test_remote_account(&abstr_origin, JUNO, STARGAZE, &mock_interchain, None)?;

        let new_name = "Funky Crazy Name";
        let new_description = "Funky new account with wonderful capabilities";
        let new_link = "https://abstract.money";

        // The user on origin chain wants to change the account description
        let ibc_action_result = origin_account.manager.execute_on_remote(
            &remote_name,
            ManagerExecuteMsg::UpdateInfo {
                name: Some(new_name.to_string()),
                description: Some(new_description.to_string()),
                link: Some(new_link.to_string()),
            },
        )?;

        mock_interchain.check_ibc(JUNO, ibc_action_result)?;

        // We check the account description changed on chain 2
        let remote_abstract_account =
            AbstractAccount::new(&abstr_remote, remote_account_id.clone());

        let account_info = remote_abstract_account.manager.info()?;

        assert_eq!(account_info.info.name, new_name.to_string());
        assert_eq!(
            account_info.info.description,
            Some(new_description.to_string())
        );
        assert_eq!(account_info.info.link, Some(new_link.to_string()));

        // Verify that remote account has been saved correctly.
        let account_response: AccountResponse =
            abstr_origin
                .ibc
                .client
                .query(&abstract_std::ibc_client::QueryMsg::Account {
                    chain: ChainName::from_chain_id(STARGAZE).to_string(),
                    account_id: AccountId::new(1, AccountTrace::Local)?,
                })?;

        assert_eq!(
            AccountResponse {
                remote_proxy_addr: remote_abstract_account.proxy.address()?.to_string(),
            },
            account_response
        );

        Ok(())
    }

    #[test]
    fn test_multi_hop_account_creation() -> AnyResult<()> {
        logger_test_init();
        let mock_interchain = MockBech32InterchainEnv::new(vec![
            (JUNO, "juno"),
            (STARGAZE, "stargaze"),
            (OSMOSIS, "osmosis"),
        ]);

        // SETUP
        let chain1 = mock_interchain.chain(JUNO).unwrap();
        let chain2 = mock_interchain.chain(STARGAZE).unwrap();
        let chain3 = mock_interchain.chain(OSMOSIS).unwrap();

        // Deploying abstract and the IBC abstract logic
        let abstr_origin = Abstract::deploy_on(chain1.clone(), chain1.sender().to_string())?;
        let abstr_intermediate_remote =
            Abstract::deploy_on(chain2.clone(), chain2.sender().to_string())?;
        let abstr_destination_remote =
            Abstract::deploy_on(chain3.clone(), chain3.sender().to_string())?;

        // Deploying polytone on both chains
        let polytone_1 = Polytone::deploy_on(chain1.clone(), None)?;
        let polytone_2 = Polytone::deploy_on(chain2.clone(), None)?;
        let polytone_3 = Polytone::deploy_on(chain3.clone(), None)?;

        // Creating a connection between 2 polytone deployments
        mock_interchain.create_contract_channel(
            &polytone_1.note,
            &polytone_2.voice,
            POLYTONE_VERSION,
            None,
        )?;

        mock_interchain.create_contract_channel(
            &polytone_2.note,
            &polytone_3.voice,
            POLYTONE_VERSION,
            None,
        )?;

        // Create the connection between client and host
        abstract_ibc_connection_with(
            &abstr_origin,
            &mock_interchain,
            &abstr_intermediate_remote,
            &polytone_1,
        )?;
        abstract_ibc_connection_with(
            &abstr_intermediate_remote,
            &mock_interchain,
            &abstr_destination_remote,
            &polytone_2,
        )?;

        // END SETUP

        // Create a local account for testing
        let account_name = TEST_ACCOUNT_NAME.to_string();
        let description = Some(TEST_ACCOUNT_DESCRIPTION.to_string());
        let link = Some(TEST_ACCOUNT_LINK.to_string());
        let origin_account: AbstractAccount<MockBech32> =
            abstr_origin.account_factory.create_new_account(
                AccountDetails {
                    name: account_name.clone(),
                    description: description.clone(),
                    link: link.clone(),
                    base_asset: None,
                    install_modules: vec![],
                    namespace: None,
                    account_id: None,
                },
                abstract_std::objects::gov_type::GovernanceDetails::Monarchy {
                    monarch: abstr_origin
                        .version_control
                        .get_chain()
                        .sender()
                        .to_string(),
                },
                None,
            )?;

        // We need to enable ibc on the account.
        origin_account.manager.update_settings(Some(true))?;

        // Now we send a message to the client saying that we want to create an account on the
        // destination chain
        let register_tx = origin_account
            .register_remote_account(&ChainName::from_chain_id(STARGAZE).to_string())?;

        mock_interchain.check_ibc(JUNO, register_tx)?;

        // Enable ibc on STARGAZE from JUNO.
        let enable_ibc_tx = origin_account.manager.execute_on_remote(
            &ChainName::from_chain_id(STARGAZE).to_string(),
            ManagerExecuteMsg::UpdateSettings {
                ibc_enabled: Some(true),
            },
        )?;

        mock_interchain.check_ibc(JUNO, enable_ibc_tx)?;

        // Create account from JUNO on OSMOSIS by going through STARGAZE
        let create_account_remote_tx = origin_account.manager.execute_on_remote_module(
            &ChainName::from_chain_id(STARGAZE).to_string(),
            PROXY,
            to_json_binary(&abstract_std::proxy::ExecuteMsg::IbcAction {
                msg: abstract_std::ibc_client::ExecuteMsg::Register {
                    host_chain: ChainName::from_chain_id(OSMOSIS).to_string(),
                    base_asset: None,
                    namespace: None,
                    install_modules: vec![],
                },
            })?,
        )?;

        mock_interchain.check_ibc(JUNO, create_account_remote_tx)?;

        let destination_remote_account_id = AccountId::new(
            origin_account.manager.config()?.account_id.seq(),
            AccountTrace::Remote(vec![
                ChainName::from_chain_id(JUNO),
                ChainName::from_chain_id(STARGAZE),
            ]),
        )?;

        let destination_remote_account = AbstractAccount::new(
            &abstr_destination_remote,
            destination_remote_account_id.clone(),
        );

        let manager_config = destination_remote_account.manager.config()?;
        assert_eq!(
            manager_config,
            ConfigResponse {
                account_id: destination_remote_account_id,
                is_suspended: false,
                module_factory_address: abstr_destination_remote.module_factory.address()?,
                version_control_address: abstr_destination_remote.version_control.address()?,
            }
        );

        Ok(())
    }

    #[test]
    fn test_create_ibc_account() -> AnyResult<()> {
        logger_test_init();

        let mock_interchain =
            MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]);

        // We just verified all steps pass
        let (abstr_origin, abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?;

        let (origin_account, remote_account_id) =
            create_test_remote_account(&abstr_origin, JUNO, STARGAZE, &mock_interchain, None)?;

        // We assert the account was created with the right properties
        let remote_abstract_account =
            AbstractAccount::new(&abstr_remote, remote_account_id.clone());
        let manager_config = remote_abstract_account.manager.config()?;
        assert_eq!(
            manager_config,
            ConfigResponse {
                account_id: remote_account_id,
                is_suspended: false,
                module_factory_address: abstr_remote.module_factory.address()?,
                version_control_address: abstr_remote.version_control.address()?,
            }
        );

        let manager_info = remote_abstract_account.manager.info()?;

        let account_name = TEST_ACCOUNT_NAME.to_string();
        let description = Some(TEST_ACCOUNT_DESCRIPTION.to_string());
        let link = Some(TEST_ACCOUNT_LINK.to_string());
        assert_eq!(
            manager_info,
            InfoResponse {
                info: abstract_std::manager::state::AccountInfo {
                    name: account_name,
                    governance_details:
                        abstract_std::objects::gov_type::GovernanceDetails::External {
                            governance_address: abstr_remote.ibc.host.address()?,
                            governance_type: "abstract-ibc".to_string()
                        },
                    chain_id: STARGAZE.to_string(),
                    description,
                    link
                }
            }
        );

        // We try to execute a message from the proxy contract (account creation for instance)

        // ii. Now we test that we can indeed create an account remotely from the interchain account
        let account_name = String::from("Abstract Test Remote Remote account");
        let create_account_remote_tx = origin_account.manager.execute_on_remote_module(
            &ChainName::from_chain_id(STARGAZE).to_string(),
            PROXY,
            to_json_binary(&abstract_std::proxy::ExecuteMsg::ModuleAction {
                msgs: vec![wasm_execute(
                    abstr_remote.account_factory.address()?,
                    &abstract_std::account_factory::ExecuteMsg::CreateAccount {
                        governance: GovernanceDetails::Monarchy {
                            monarch: abstr_remote.version_control.address()?.to_string(),
                        },
                        name: account_name.clone(),
                        description: None,
                        link: None,
                        account_id: None,
                        base_asset: None,
                        namespace: None,
                        install_modules: vec![],
                    },
                    vec![],
                )?
                .into()],
            })?,
        )?;

        // The create remote account tx is passed ?
        mock_interchain.check_ibc(JUNO, create_account_remote_tx)?;

        // Can get the account from stargaze.
        let created_account_id = AccountId::new(1, AccountTrace::Local)?;

        let created_abstract_account = AbstractAccount::new(&abstr_remote, created_account_id);

        let account_info: AccountInfo<Addr> = created_abstract_account.manager.info()?.info;

        assert_eq!(
            AccountInfo {
                chain_id: STARGAZE.to_owned(),
                governance_details: GovernanceDetails::Monarchy {
                    monarch: abstr_remote.version_control.address()?.to_string(),
                },
                description: None,
                name: account_name,
                link: None,
            },
            account_info.into()
        );

        Ok(())
    }

    #[test]
    fn test_cannot_create_remote_account_when_caller_is_not_host() -> AnyResult<()> {
        let mock_interchain =
            MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]);
        let stargaze = mock_interchain.chain(STARGAZE)?;

        let (_abstr_origin, abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?;

        try_create_remote_account(&abstr_remote, &stargaze.addr_make("user")).unwrap_err();

        try_create_remote_account(&abstr_remote, &abstr_remote.ibc.host.address()?)?;

        Ok(())
    }

    fn try_create_remote_account(
        abstr: &Abstract<MockBech32>,
        sender: &Addr,
    ) -> AnyResult<AppResponse> {
        Ok(abstr.account_factory.call_as(sender).create_account(
            GovernanceDetails::Monarchy {
                monarch: abstr
                    .account_factory
                    .get_chain()
                    .addr_make("user")
                    .to_string(),
            },
            vec![],
            String::from("name"),
            Some(AccountId::new(
                2,
                AccountTrace::Remote(vec![ChainName::from_chain_id(JUNO)]),
            )?),
            None,
            None,
            None,
            None,
            &[],
        )?)
    }

    #[test]
    fn test_cannot_call_remote_manager_from_non_host_account() -> AnyResult<()> {
        logger_test_init();
        let mock_interchain =
            MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]);

        // We just verified all steps pass
        let (abstr_juno, abstr_stargaze) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?;

        let (_origin_account, remote_account_id) =
            create_test_remote_account(&abstr_juno, JUNO, STARGAZE, &mock_interchain, None)?;

        let remote_account = AbstractAccount::new(&abstr_stargaze, remote_account_id);

        let new_name = String::from("Funky Crazy Name");
        let new_description = String::from("Funky new account with wonderful capabilities");
        let new_link = String::from("https://abstract.money");

        // Cannot call with sender that is not host.
        let result = remote_account
            .manager
            .call_as(&mock_interchain.chain(STARGAZE)?.sender())
            .update_info(
                Some(new_description.clone()),
                Some(new_link.clone()),
                Some(new_name.clone()),
            );

        assert!(result.is_err());

        // Can call with host.
        let result = remote_account
            .manager
            .call_as(&abstr_stargaze.ibc.host.address()?)
            .update_info(Some(new_description), Some(new_link), Some(new_name));

        assert!(result.is_ok());

        Ok(())
    }

    #[test]
    fn test_cannot_call_ibc_host_directly_with_remove_chain_proxy() -> AnyResult<()> {
        logger_test_init();
        let mock_interchain =
            MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]);

        // We just verified all steps pass
        let (_abstr_origin, abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?;

        let result = abstr_remote
            .ibc
            .host
            .call_as(&Addr::unchecked("rando"))
            .remove_chain_proxy(ChainName::from_chain_id(STARGAZE).to_string());

        assert!(result.is_err());

        Ok(())
    }

    #[test]
    fn test_cannot_call_ibc_host_directly_with_register_chain_proxy() -> AnyResult<()> {
        logger_test_init();
        let mock_interchain =
            MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]);

        // We just verified all steps pass
        let (_abstr_origin, abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?;

        let result = abstr_remote
            .ibc
            .host
            .call_as(&Addr::unchecked("rando"))
            .register_chain_proxy(
                ChainName::from_chain_id(OSMOSIS).to_string(),
                PROXY.to_owned(),
            );
        assert!(result.is_err());

        Ok(())
    }

    #[test]
    fn test_cannot_call_ibc_host_directly_with_dispatch_action() -> AnyResult<()> {
        logger_test_init();
        let mock_interchain =
            MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]);

        // We just verified all steps pass
        let (abstr_origin, abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?;

        let (origin_account, remote_account_id) =
            create_test_remote_account(&abstr_origin, JUNO, STARGAZE, &mock_interchain, None)?;

        let result = abstr_remote.ibc.host.execute(
            &HostExecuteMsg::Execute {
                account_id: remote_account_id,
                proxy_address: origin_account.proxy.address()?.to_string(),
                action: HostAction::Dispatch {
                    manager_msgs: vec![ManagerExecuteMsg::UpdateInfo {
                        name: Some("name".to_owned()),
                        description: Some("description".to_owned()),
                        link: Some("link".to_owned()),
                    }],
                },
            },
            None,
        );

        assert!(result.is_err());

        Ok(())
    }

    #[test]
    fn test_cannot_call_ibc_host_directly_with_internal_action() -> AnyResult<()> {
        logger_test_init();
        let mock_interchain =
            MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]);

        // We just verified all steps pass
        let (abstr_origin, abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?;

        let (origin_account, remote_account_id) =
            create_test_remote_account(&abstr_origin, JUNO, STARGAZE, &mock_interchain, None)?;

        let result = abstr_remote.ibc.host.execute(
            &HostExecuteMsg::Execute {
                account_id: remote_account_id,
                proxy_address: origin_account.proxy.address()?.to_string(),
                action: HostAction::Internal(InternalAction::Register {
                    name: "name".to_owned(),
                    description: None,
                    link: None,
                    base_asset: None,
                    namespace: None,
                    install_modules: vec![],
                }),
            },
            None,
        );

        assert!(result.is_err());

        Ok(())
    }

    #[test]
    fn test_cannot_call_ibc_host_directly_with_helper_action() -> AnyResult<()> {
        logger_test_init();
        let mock_interchain =
            MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]);

        // We just verified all steps pass
        let (abstr_origin, abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?;

        let (origin_account, remote_account_id) =
            create_test_remote_account(&abstr_origin, JUNO, STARGAZE, &mock_interchain, None)?;

        let result = abstr_remote.ibc.host.execute(
            &HostExecuteMsg::Execute {
                account_id: remote_account_id,
                proxy_address: origin_account.proxy.address()?.to_string(),
                action: HostAction::Helpers(HelperAction::SendAllBack),
            },
            None,
        );

        assert!(result.is_err());

        Ok(())
    }

    #[test]
    fn test_send_all_back() -> AnyResult<()> {
        logger_test_init();
        let mock_interchain =
            MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]);
        let origin_denom = "ujuno";
        let remote_denom: &str = &format!("ibc/channel-0/{}", origin_denom);

        // We just verified all steps pass
        let (abstr_origin, abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?;

        mock_interchain.chain(JUNO)?.set_balance(
            &abstr_origin.version_control.get_chain().sender(),
            coins(100, origin_denom),
        )?;
        let (origin_account, remote_account_id) = create_test_remote_account(
            &abstr_origin,
            JUNO,
            STARGAZE,
            &mock_interchain,
            Some(coins(10, origin_denom)),
        )?;

        //let interchain_channel = create_transfer_channel(JUNO, STARGAZE, &mock_interchain)?;

        let interchain_channel = mock_interchain.create_channel(
            JUNO,
            STARGAZE,
            &PortId::transfer(),
            &PortId::transfer(),
            "ics20-1",
            None, // Unordered channel
        )?;

        abstr_origin.ans_host.update_channels(
            vec![(
                UncheckedChannelEntry {
                    connected_chain: "stargaze".to_string(),
                    protocol: ICS20.to_string(),
                },
                interchain_channel
                    .interchain_channel
                    .get_chain(JUNO)?
                    .channel
                    .unwrap()
                    .to_string(),
            )],
            vec![],
        )?;

        abstr_remote.ans_host.update_channels(
            vec![(
                UncheckedChannelEntry {
                    connected_chain: "juno".to_string(),
                    protocol: ICS20.to_string(),
                },
                interchain_channel
                    .interchain_channel
                    .get_chain(STARGAZE)?
                    .channel
                    .unwrap()
                    .to_string(),
            )],
            vec![],
        )?;

        // Verify origin balance before sending funds.
        let origin_balance = mock_interchain
            .chain(JUNO)?
            .query_balance(&origin_account.proxy.address()?, origin_denom)?;
        assert_eq!(Uint128::from(10u128), origin_balance);

        // Send funds from juno to stargaze.
        let send_funds_tx = origin_account.manager.execute_on_module(
            PROXY,
            abstract_std::proxy::ExecuteMsg::IbcAction {
                msg: abstract_std::ibc_client::ExecuteMsg::SendFunds {
                    funds: coins(10, origin_denom),
                    host_chain: ChainName::from_chain_id(STARGAZE).to_string(),
                },
            },
        )?;

        mock_interchain.check_ibc(JUNO, send_funds_tx)?;

        // Verify local balance after sending funds.
        let origin_balance = mock_interchain
            .chain(JUNO)?
            .query_balance(&origin_account.proxy.address()?, origin_denom)?;
        assert!(origin_balance.is_zero());

        let remote_account = AbstractAccount::new(&abstr_remote, remote_account_id.clone());

        // Check balance on remote chain.
        let remote_balance = mock_interchain
            .chain(STARGAZE)?
            .query_balance(&remote_account.proxy.address()?, remote_denom)?;
        assert_eq!(Uint128::from(10u128), remote_balance);

        // Send all back.
        let send_funds_back_tx = origin_account
            .manager
            .send_all_funds_back(&ChainName::from_chain_id(STARGAZE).to_string())?;

        mock_interchain.check_ibc(JUNO, send_funds_back_tx)?;

        // Check balance on remote chain.
        let remote_balance = mock_interchain
            .chain(STARGAZE)?
            .query_balance(&remote_account.proxy.address()?, remote_denom)?;
        assert!(remote_balance.is_zero());

        // Check balance on local chain.
        let origin_balance = mock_interchain
            .chain(JUNO)?
            .query_balance(&origin_account.proxy.address()?, origin_denom)?;
        assert_eq!(Uint128::from(10u128), origin_balance);

        Ok(())
    }
}