|
2 | 2 |
|
3 | 3 | use anyhow::Result; |
4 | 4 | use async_trait::async_trait; |
5 | | -use integration_utils::integration_contract::IntegrationContract; |
6 | | -use near_workspaces::Account; |
| 5 | +use helper_contract::{ |
| 6 | + api::HelperApiIntegration, |
| 7 | + interface::{HelperContract, HELPER_CONTRACT}, |
| 8 | +}; |
| 9 | +use integration_utils::{integration_contract::IntegrationContract, misc::ToNear}; |
| 10 | +use model::lockup_api::LockupApiIntegration; |
| 11 | +use multisig_integration::{Multisig, MULTISIG}; |
| 12 | +use multisig_model::api::MultisigApiIntegration; |
| 13 | +use near_workspaces::{types::NearToken, Account}; |
| 14 | +use sweat_integration::{SweatFt, FT_CONTRACT}; |
| 15 | +use sweat_model::{StorageManagementIntegration, SweatApiIntegration}; |
7 | 16 |
|
8 | | -use crate::lockup_interface::{LockupContract, LOCKUP_CONTRACT}; |
| 17 | +use crate::lockup_interface::{GetContractAccount, LockupContract}; |
| 18 | + |
| 19 | +pub const LOCKUP_CONTRACT: &str = "ft_lockup_original"; |
9 | 20 |
|
10 | 21 | pub type Context = integration_utils::context::Context<near_workspaces::network::Sandbox>; |
11 | 22 |
|
12 | 23 | #[async_trait] |
13 | 24 | pub trait IntegrationContext { |
14 | 25 | async fn manager(&mut self) -> Result<Account>; |
| 26 | + async fn bob(&mut self) -> Result<Account>; |
15 | 27 | async fn alice(&mut self) -> Result<Account>; |
16 | | - async fn fee(&mut self) -> Result<Account>; |
17 | 28 | fn lockup(&self) -> LockupContract<'_>; |
| 29 | + fn multisig(&self) -> Multisig<'_>; |
| 30 | + fn ft_contract(&self) -> SweatFt<'_>; |
| 31 | + fn helper(&self) -> HelperContract<'_>; |
18 | 32 | } |
19 | 33 |
|
20 | 34 | #[async_trait] |
21 | 35 | impl IntegrationContext for Context { |
22 | 36 | async fn manager(&mut self) -> Result<Account> { |
23 | | - self.account("manager").await |
| 37 | + let name = "manager"; |
| 38 | + |
| 39 | + if !self.accounts.contains_key(name) { |
| 40 | + let root_account = self.worker.dev_create_account().await?; |
| 41 | + |
| 42 | + let account = root_account |
| 43 | + .create_subaccount(name) |
| 44 | + .initial_balance(NearToken::from_near(50)) |
| 45 | + .transact() |
| 46 | + .await? |
| 47 | + .into_result()?; |
| 48 | + |
| 49 | + self.accounts.insert(name.to_string(), account); |
| 50 | + } |
| 51 | + |
| 52 | + Ok(self.accounts.get(name).unwrap().clone()) |
24 | 53 | } |
25 | 54 |
|
26 | | - async fn alice(&mut self) -> Result<Account> { |
27 | | - self.account("alice").await |
| 55 | + async fn bob(&mut self) -> Result<Account> { |
| 56 | + self.account("bob").await |
28 | 57 | } |
29 | 58 |
|
30 | | - async fn fee(&mut self) -> Result<Account> { |
31 | | - self.account("fee").await |
| 59 | + async fn alice(&mut self) -> Result<Account> { |
| 60 | + self.account("alice").await |
32 | 61 | } |
33 | 62 |
|
34 | 63 | fn lockup(&self) -> LockupContract<'_> { |
35 | 64 | LockupContract::with_contract(&self.contracts[LOCKUP_CONTRACT]) |
36 | 65 | } |
| 66 | + |
| 67 | + fn multisig(&self) -> Multisig<'_> { |
| 68 | + Multisig::with_contract(&self.contracts[MULTISIG]) |
| 69 | + } |
| 70 | + |
| 71 | + fn ft_contract(&self) -> SweatFt<'_> { |
| 72 | + SweatFt::with_contract(&self.contracts[FT_CONTRACT]) |
| 73 | + } |
| 74 | + |
| 75 | + fn helper(&self) -> HelperContract<'_> { |
| 76 | + HelperContract::new(&self.contracts[HELPER_CONTRACT]) |
| 77 | + } |
37 | 78 | } |
38 | 79 |
|
39 | 80 | pub(crate) async fn prepare_contract() -> Result<Context> { |
40 | | - let context = Context::new(&[LOCKUP_CONTRACT], "build-integration".into()).await?; |
41 | | - //context.lockup().new().await?; |
| 81 | + let mut context = Context::new( |
| 82 | + &[LOCKUP_CONTRACT, MULTISIG, FT_CONTRACT, HELPER_CONTRACT], |
| 83 | + "build-integration".into(), |
| 84 | + ) |
| 85 | + .await?; |
| 86 | + |
| 87 | + let manager = context.manager().await?; |
| 88 | + |
| 89 | + context |
| 90 | + .ft_contract() |
| 91 | + .new(".u.sweat.testnet".to_string().into()) |
| 92 | + .call() |
| 93 | + .await?; |
| 94 | + context.ft_contract().add_oracle(&manager.to_near()).call().await?; |
| 95 | + |
| 96 | + context.multisig().new(0).call().await?; |
| 97 | + |
| 98 | + context |
| 99 | + .ft_contract() |
| 100 | + .tge_mint(&manager.to_near(), NearToken::from_near(100).as_near().into()) |
| 101 | + .call() |
| 102 | + .await?; |
| 103 | + |
| 104 | + context |
| 105 | + .ft_contract() |
| 106 | + .storage_deposit(context.lockup().contract_account().into(), None) |
| 107 | + .call() |
| 108 | + .await?; |
| 109 | + |
| 110 | + context |
| 111 | + .lockup() |
| 112 | + .new( |
| 113 | + context.ft_contract().contract_account(), |
| 114 | + vec![manager.to_near()], |
| 115 | + Some(vec![manager.to_near()]), |
| 116 | + manager.to_near(), |
| 117 | + ) |
| 118 | + .call() |
| 119 | + .await?; |
| 120 | + |
| 121 | + context.helper().new().result().await?; |
| 122 | + |
42 | 123 | Ok(context) |
43 | 124 | } |
0 commit comments