Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fc1943s committed Sep 4, 2024
1 parent 01804a7 commit 1110c52
Show file tree
Hide file tree
Showing 13 changed files with 35,116 additions and 2,104 deletions.
2 changes: 1 addition & 1 deletion apps/chat/contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ inline_colorization = { workspace = true }
fable_library_rust = { workspace = true }
borsh = "1.5"
multibase = ">=0.9,<1"
near-sdk = "5.1"
near-sdk = "5.3"
sha2 = "~0.11.0-pre.4"
unsigned-varint = ">=0.8,<1"
15 changes: 15 additions & 0 deletions apps/chat/contract/chat_contract.dib
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,21 @@ inl claim_alias (state : rust.ref (rust.mut' state)) (alias : sm'.std_string) :
!\\(version, $'$"&mut ($0, !alias_map, !account_map)"')
)

#!spiral

//// test
///! rust -c=-e

""
|> sm'.to_std_string
|> claim_alias (
inl state = new ()
inl version = state.version
inl alias_map = state.alias_map
inl account_map = state.account_map
!\\(version, $'$"&mut ($0, !alias_map, !account_map)"')
)

#!markdown

### main
Expand Down
243 changes: 113 additions & 130 deletions apps/chat/contract/chat_contract.dib.html

Large diffs are not rendered by default.

240 changes: 111 additions & 129 deletions apps/chat/contract/chat_contract.dib.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/chat/contract/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ repository.workspace = true
serde_json = { workspace = true }
tokio = { workspace = true }
anyhow = "1.0"
near-sdk = "5.3"
near-workspaces = { version = "=0.11.1", features = ["experimental", "unstable"] }
near-sandbox-utils = { version = ">=0.10.1,<1", features = ["global_install"] }

56 changes: 27 additions & 29 deletions apps/chat/contract/tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use near_workspaces::AccountId;
use serde_json::json;
use std::collections::HashMap;

// const GAS_PRICE_IN_NEAR: f64 = 0.0001;
Expand Down Expand Up @@ -51,7 +49,7 @@ async fn main() -> anyhow::Result<()> {
// claim_alias(contract, '')
let result = contract
.call("claim_alias")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "",
}))
.transact()
Expand All @@ -78,7 +76,7 @@ async fn main() -> anyhow::Result<()> {
// claim_alias(account1, alias1)
let result = account1
.call(contract_id, "claim_alias")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias1",
}))
.transact()
Expand All @@ -89,7 +87,7 @@ async fn main() -> anyhow::Result<()> {
// claim_alias(account1, alias1)
let result = account1
.call(contract_id, "claim_alias")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias1",
}))
.transact()
Expand All @@ -100,7 +98,7 @@ async fn main() -> anyhow::Result<()> {
// get_account_info(account1)
let result: Option<(String, (u64, u32))> = account1
.view(contract_id, "get_account_info")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"account_id": account1.id(),
}))
.await?
Expand All @@ -117,9 +115,9 @@ async fn main() -> anyhow::Result<()> {
}

// get_alias_map(account1, alias1)
let result: Option<HashMap<AccountId, (u64, u32)>> = account1
let result: Option<HashMap<near_workspaces::AccountId, (u64, u32)>> = account1
.view(contract_id, "get_alias_map")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias1",
}))
.await?
Expand Down Expand Up @@ -147,7 +145,7 @@ async fn main() -> anyhow::Result<()> {
// claim_alias(account2, alias2)
let result = account2
.call(contract_id, "claim_alias")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias2",
}))
.transact()
Expand All @@ -158,7 +156,7 @@ async fn main() -> anyhow::Result<()> {
// get_account_info(account2)
let result: Option<(String, (u64, u32))> = account2
.view(contract_id, "get_account_info")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"account_id": account2.id(),
}))
.await?
Expand All @@ -175,7 +173,7 @@ async fn main() -> anyhow::Result<()> {
}

// get_alias_map_borsh(alias2)
let result: Option<HashMap<AccountId, (u64, u32)>> = account2
let result: Option<HashMap<near_workspaces::AccountId, (u64, u32)>> = account2
.view(contract_id, "get_alias_map_borsh")
.args_borsh("alias2")
.await?
Expand All @@ -199,7 +197,7 @@ async fn main() -> anyhow::Result<()> {
// claim_alias(account2, alias1)
let result = account2
.call(contract_id, "claim_alias")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias1",
}))
.transact()
Expand All @@ -210,7 +208,7 @@ async fn main() -> anyhow::Result<()> {
// get_account_info(account2)
let result: Option<(String, (u64, u32))> = account2
.view(contract_id, "get_account_info")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"account_id": account2.id(),
}))
.await?
Expand All @@ -227,9 +225,9 @@ async fn main() -> anyhow::Result<()> {
}

// get_alias_map(account2, alias1)
let result: Option<HashMap<AccountId, (u64, u32)>> = account2
let result: Option<HashMap<near_workspaces::AccountId, (u64, u32)>> = account2
.view(contract_id, "get_alias_map")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias1",
}))
.await?
Expand Down Expand Up @@ -257,9 +255,9 @@ async fn main() -> anyhow::Result<()> {
}

// get_alias_map(account2, alias2)
let result: Option<HashMap<AccountId, (u64, u32)>> = account2
let result: Option<HashMap<near_workspaces::AccountId, (u64, u32)>> = account2
.view(contract_id, "get_alias_map")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias2",
}))
.await?
Expand All @@ -280,7 +278,7 @@ async fn main() -> anyhow::Result<()> {
// claim_alias(account1, alias2)
let result = account1
.call(contract_id, "claim_alias")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias2",
}))
.transact()
Expand All @@ -291,7 +289,7 @@ async fn main() -> anyhow::Result<()> {
// get_account_info(account1)
let result: Option<(String, (u64, u32))> = account1
.view(contract_id, "get_account_info")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"account_id": account1.id(),
}))
.await?
Expand All @@ -308,9 +306,9 @@ async fn main() -> anyhow::Result<()> {
}

// get_alias_map(account1, alias2)
let result: Option<HashMap<AccountId, (u64, u32)>> = account1
let result: Option<HashMap<near_workspaces::AccountId, (u64, u32)>> = account1
.view(contract_id, "get_alias_map")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias2",
}))
.await?
Expand All @@ -332,9 +330,9 @@ async fn main() -> anyhow::Result<()> {
}

// get_alias_map(account1, alias1)
let result: Option<HashMap<AccountId, (u64, u32)>> = account1
let result: Option<HashMap<near_workspaces::AccountId, (u64, u32)>> = account1
.view(contract_id, "get_alias_map")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias1",
}))
.await?
Expand All @@ -358,7 +356,7 @@ async fn main() -> anyhow::Result<()> {
// claim_alias(account1, alias1)
let result = account1
.call(contract_id, "claim_alias")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias1",
}))
.transact()
Expand All @@ -369,7 +367,7 @@ async fn main() -> anyhow::Result<()> {
// get_account_info(account1)
let result: Option<(String, (u64, u32))> = account1
.view(contract_id, "get_account_info")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"account_id": account1.id(),
}))
.await?
Expand All @@ -386,9 +384,9 @@ async fn main() -> anyhow::Result<()> {
}

// get_alias_map(account1, alias1)
let result: Option<HashMap<AccountId, (u64, u32)>> = account1
let result: Option<HashMap<near_workspaces::AccountId, (u64, u32)>> = account1
.view(contract_id, "get_alias_map")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias1",
}))
.await?
Expand Down Expand Up @@ -416,9 +414,9 @@ async fn main() -> anyhow::Result<()> {
}

// get_alias_map(account1, alias2)
let result: Option<HashMap<AccountId, (u64, u32)>> = account1
let result: Option<HashMap<near_workspaces::AccountId, (u64, u32)>> = account1
.view(contract_id, "get_alias_map")
.args_json(json!({
.args_json(near_sdk::serde_json::json!({
"alias": "alias2",
}))
.await?
Expand Down
27 changes: 21 additions & 6 deletions apps/spiral/wasm/spiral_wasm.dib
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ open sm'_operators

inl get_args () =
{
exception = "exception", 'e'
trace_level = "trace_level", 't'
wasm = "wasm", 'w'
}
Expand All @@ -38,6 +39,9 @@ let get_command () =
##"command"
|> runtime.new_command
|> runtime.command_args_override_self true
|> runtime.command_init_arg (get_args () .exception) (
runtime.arg_action runtime.SetTrue
)
|> runtime.command_init_arg (get_args () .trace_level) (
real runtime.arg_union `trace_level ignore
)
Expand Down Expand Up @@ -420,7 +424,7 @@ inl print_usd retry (result : execution_final_result) =

#!spiral

let rec run (matches : runtime.arg_matches) : async.future_pin (resultm.result' () resultm.anyhow_error) =
let rec run (matches : runtime.arg_matches) : async.future_pin (resultm.result' u8 resultm.anyhow_error) =
fun () =>
inl wasm_path =
matches
Expand Down Expand Up @@ -523,7 +527,7 @@ let rec run (matches : runtime.arg_matches) : async.future_pin (resultm.result'
trace Verbose (fun () => "spiral_wasm.run") fun () => { retries }

match retries with
| Ok _retries => Ok () |> resultm.box
| Ok retries => Ok retries |> resultm.box
| Error retries => { retries } |> sm'.format |> resultm.anyhow_error |> resultm.err

|> async.new_future_move
Expand Down Expand Up @@ -557,10 +561,21 @@ inl main (args : array_base string) =
fun () => $'$"spiral_wasm.main"'
fun () => { args }

arg_matches
|> run
|> async.block_on
|> resultm.unwrap'
inl exception : bool =
arg_matches
|> runtime.matches_get_flag (get_args () .exception |> fst)

inl result =
arg_matches
|> run
|> async.block_on
|> resultm.map_error' sm'.format'

match result |> resultm.ok' |> optionm'.unbox with
| Some retries when exception => "spiral_wasm.main / exception=true" |> resultm.err |> resultm.unwrap'
| None when exception => ()
| Some retries => retries |> ignore
| None => result |> resultm.unwrap' |> ignore

0i32

Expand Down
Loading

0 comments on commit 1110c52

Please sign in to comment.