Skip to content

Commit

Permalink
Update Integration utils (#49)
Browse files Browse the repository at this point in the history
There was no need for 2 methods `call_contract` and `call_user`.

---------

Co-authored-by: Vasily Styagov <styagov.dev@gmail.com>
  • Loading branch information
VladasZ and vasyafromrussia authored Nov 29, 2023
1 parent 2aab04a commit 1f721c2
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test

on:
pull_request:
branches: [ main ]
branches: [ main, dev ]

env:
CARGO_TERM_COLOR: always
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ near-workspaces = "0.9.0"

near-sdk = { git = "https://github.com/sweatco/near-sdk-rs", rev = "8c48b26cc48d969c1e5f3162141fe9c824fccecd" }
near-contract-standards = { git = "https://github.com/sweatco/near-sdk-rs", rev = "8c48b26cc48d969c1e5f3162141fe9c824fccecd" }
integration-trait = { git = "https://github.com/sweatco/integration-trait.git", rev = "83a69f7ba4acab9405bf935f7dfc70f2f5279c40" }
integration-utils = { git = "https://github.com/sweatco/integration-utils.git", rev = "1b05c03351009c901a45400687c24f685f8b81c3" }
integration-trait = { git = "https://github.com/sweatco/integration-trait.git", rev = "8dd8b63cef5e60448629a8903ea43b642bbf9f45" }
integration-utils = { git = "https://github.com/sweatco/integration-utils.git", rev = "9fe6398c6064dfe8a26c323a6d0ea3c117a0b4a5" }

sweat-model = { path = "model" }
sweat-integration = { path = "sweat-integration" }
5 changes: 4 additions & 1 deletion integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ async fn happy_flow() -> anyhow::Result<()> {
context
.ft_contract()
.with_user(&oracle)
.defer_batch(vec![(alice.to_near(), 1000)], oracle.to_near())
.defer_batch(
vec![(alice.to_near(), 1000)],
context.holding_contract().as_account().to_near(),
)
.await?;

Ok(())
Expand Down
Binary file modified res/defer_stub.wasm
Binary file not shown.
Binary file modified res/sweat.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.73"
channel = "1.74"
27 changes: 13 additions & 14 deletions sweat-integration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl FungibleTokenCoreIntegration for SweatFt<'_> {

let result = self
.user_account()
.unwrap()
.call(self.contract.id(), "ft_transfer")
.args_json(args)
.max_gas()
Expand Down Expand Up @@ -67,6 +68,7 @@ impl FungibleTokenCoreIntegration for SweatFt<'_> {

let result = self
.user_account()
.unwrap()
.call(self.contract.id(), "ft_transfer_call")
.args_json(args)
.max_gas()
Expand All @@ -83,13 +85,13 @@ impl FungibleTokenCoreIntegration for SweatFt<'_> {
}

async fn ft_total_supply(&self) -> Result<U128> {
self.call_contract("ft_total_supply", ()).await
self.call("ft_total_supply", ()).await
}

async fn ft_balance_of(&self, account_id: AccountId) -> Result<U128> {
println!(">> Run ft_balance_of for {account_id}");

self.call_contract(
self.call(
"ft_balance_of",
json!({
"account_id": account_id,
Expand Down Expand Up @@ -148,7 +150,7 @@ impl StorageManagementIntegration for SweatFt<'_> {
#[async_trait]
impl SweatDeferIntegration for SweatFt<'_> {
async fn defer_batch(&mut self, steps_batch: Vec<(AccountId, u32)>, holding_account_id: AccountId) -> Result<()> {
self.call_user(
self.call(
"defer_batch",
json!({
"steps_batch": steps_batch,
Expand All @@ -162,7 +164,7 @@ impl SweatDeferIntegration for SweatFt<'_> {
#[async_trait]
impl SweatApiIntegration for SweatFt<'_> {
async fn new(&self, postfix: Option<String>) -> Result<()> {
self.call_contract(
self.call(
"new",
json!({
"postfix": postfix,
Expand All @@ -172,7 +174,7 @@ impl SweatApiIntegration for SweatFt<'_> {
}

async fn add_oracle(&mut self, account_id: &AccountId) -> Result<()> {
self.call_contract(
self.call(
"add_oracle",
json!({
"account_id": account_id,
Expand All @@ -190,7 +192,7 @@ impl SweatApiIntegration for SweatFt<'_> {
}

async fn tge_mint(&mut self, account_id: &AccountId, amount: U128) -> anyhow::Result<()> {
self.call_contract(
self.call(
"tge_mint",
json!({
"account_id": account_id,
Expand All @@ -209,11 +211,11 @@ impl SweatApiIntegration for SweatFt<'_> {
}

async fn get_steps_since_tge(&self) -> Result<U64> {
self.call_contract("get_steps_since_tge", ()).await
self.call("get_steps_since_tge", ()).await
}

async fn record_batch(&mut self, steps_batch: Vec<(AccountId, u32)>) -> anyhow::Result<()> {
self.call_user(
self.call(
"record_batch",
json!({
"steps_batch": steps_batch,
Expand All @@ -223,7 +225,7 @@ impl SweatApiIntegration for SweatFt<'_> {
}

async fn formula(&self, steps_since_tge: U64, steps: u32) -> anyhow::Result<U128> {
self.call_contract(
self.call(
"formula",
json!({
"steps_since_tge": steps_since_tge,
Expand Down Expand Up @@ -257,11 +259,8 @@ impl<'a> IntegrationContract<'a> for SweatFt<'a> {
self
}

fn user_account(&self) -> Account {
self.account
.as_ref()
.expect("Set account with `user` method first")
.clone()
fn user_account(&self) -> Option<Account> {
self.account.clone()
}

fn contract(&self) -> &'a Contract {
Expand Down

0 comments on commit 1f721c2

Please sign in to comment.