Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
garikbesson committed Aug 7, 2024
1 parent 966b9c9 commit 6f5c514
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 53 deletions.
2 changes: 1 addition & 1 deletion contract-simple-rs/src/external_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ use near_sdk::ext_contract;
trait HelloNear {
fn get_greeting(&self) -> String;
fn set_greeting(&self, greeting: String);
}
}
4 changes: 2 additions & 2 deletions contract-simple-rs/src/high_level.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Find all our documentation at https://docs.near.org
use near_sdk::{env, log, near, Promise, PromiseError};

use crate::{Contract, ContractExt, hello_near, FIVE_TGAS};
use crate::{hello_near, Contract, ContractExt, FIVE_TGAS};

#[near]
impl Contract {
Expand Down Expand Up @@ -64,4 +64,4 @@ impl Contract {
true
}
}
}
}
2 changes: 1 addition & 1 deletion contract-simple-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Find all our documentation at https://docs.near.org
use near_sdk::{env, near, AccountId, Gas, PanicOnDefault, NearToken};
use near_sdk::{env, near, AccountId, Gas, NearToken, PanicOnDefault};

pub mod external_contract;
pub use crate::external_contract::*;
Expand Down
10 changes: 4 additions & 6 deletions contract-simple-rs/src/low_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Contract {
"get_greeting".to_owned(),
NO_ARGS,
NO_DEPOSIT,
TEN_TGAS
TEN_TGAS,
);

hello_promise.then(
Expand Down Expand Up @@ -40,14 +40,12 @@ impl Contract {

// Public - change external greeting
pub fn ll_change_greeting(&mut self, new_greeting: String) -> Promise {
let args = json!({ "greeting": new_greeting })
.to_string()
.into_bytes();
let args = json!({ "greeting": new_greeting }).to_string().into_bytes();
let hello_promise = Promise::new(self.hello_account.clone()).function_call(
"set_greeting".to_owned(),
args,
NO_DEPOSIT,
TEN_TGAS
TEN_TGAS,
);

hello_promise.then(
Expand All @@ -72,4 +70,4 @@ impl Contract {
true
}
}
}
}
86 changes: 43 additions & 43 deletions contract-simple-rs/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use near_workspaces::{types::NearToken, Account, Contract};
use serde_json::json;

#[tokio::test]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let worker = near_workspaces::sandbox().await?;
Expand All @@ -10,7 +10,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Deploy contract for testing
let contract_wasm = near_workspaces::compile_project("./").await?;
let contract = worker.dev_deploy(&contract_wasm).await?;

// Create accounts
let account = worker.dev_create_account().await?;
let alice = account
Expand All @@ -27,7 +27,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.transact()
.await?
.into_result()?;

// Begin tests
test_hl_default_greeting(&alice, &contract).await?;
test_hl_change_greeting(&alice, &contract).await?;
Expand All @@ -46,59 +46,59 @@ async fn test_hl_default_greeting(
.transact()
.await?
.json()?;

assert_eq!(greeting, "Hello".to_string());
Ok(())
}

async fn test_hl_change_greeting(
user: &Account,
contract: &Contract,
user: &Account,
contract: &Contract,
) -> Result<(), Box<dyn std::error::Error>> {
let result: bool = user
.call(contract.id(), "hl_change_greeting")
.args_json(json!({ "new_greeting": "Howdy" }))
.max_gas()
.transact()
.await?
.json()?;
let result: bool = user
.call(contract.id(), "hl_change_greeting")
.args_json(json!({ "new_greeting": "Howdy" }))
.max_gas()
.transact()
.await?
.json()?;

assert!(result);
assert!(result);

let greeting: String = user
.call(contract.id(), "hl_query_greeting")
.args_json(json!({}))
.max_gas()
.transact()
.await?
.json()?;
let greeting: String = user
.call(contract.id(), "hl_query_greeting")
.args_json(json!({}))
.max_gas()
.transact()
.await?
.json()?;

assert_eq!(greeting, "Howdy".to_string());
Ok(())
assert_eq!(greeting, "Howdy".to_string());
Ok(())
}

async fn test_ll_change_greeting(
user: &Account,
contract: &Contract,
user: &Account,
contract: &Contract,
) -> Result<(), Box<dyn std::error::Error>> {
let result: bool = user
.call(contract.id(), "ll_change_greeting")
.args_json(json!({ "new_greeting": "Hello" }))
.max_gas()
.transact()
.await?
.json()?;
let result: bool = user
.call(contract.id(), "ll_change_greeting")
.args_json(json!({ "new_greeting": "Hello" }))
.max_gas()
.transact()
.await?
.json()?;

assert!(result);
assert!(result);

let greeting: String = user
.call(contract.id(), "ll_query_greeting")
.args_json(json!({}))
.max_gas()
.transact()
.await?
.json()?;
let greeting: String = user
.call(contract.id(), "ll_query_greeting")
.args_json(json!({}))
.max_gas()
.transact()
.await?
.json()?;

assert_eq!(greeting, "Hello".to_string());
Ok(())
}
assert_eq!(greeting, "Hello".to_string());
Ok(())
}

0 comments on commit 6f5c514

Please sign in to comment.