-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from matiasbenary/update-and-reorganize
feat: update and reorganize repo
- Loading branch information
Showing
60 changed files
with
231 additions
and
1,045 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Rust | ||
./contract-rs/target/ | ||
./contract-rs/Cargo.lock | ||
|
||
# TypeScript - Sandbox | ||
./contract-ts/sandbox-ts/package-lock.json | ||
./contract-ts/sandbox-ts/node_modules/ | ||
|
||
# TypeScript | ||
./contract-ts/build/ | ||
./contract-ts/node_modules/ | ||
./contract-ts/sandbox-ts/node_modules/ | ||
./contract-ts/sandbox-ts/yarn.lock | ||
./contract-ts/yarn.lock | ||
./contract-ts/package-lock.json | ||
|
||
# Frontend | ||
./frontend/dist/ | ||
./frontend/node_modules/ | ||
./frontend/.parcel-cache | ||
./frontend/yarn.lock | ||
./frontend/package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
# Hello World Examples | ||
|
||
This repository contains examples of a simple Hello World smart contract in both JavaScript and Rust. | ||
This repository contains examples of a simple Hello World smart contract in both JavaScript and Rust, and an examples of a frontend interacting with a Hello World smart contract. | ||
|
||
## Repositories | ||
|
||
- [Hello World JavaScript](hello-near-js) | ||
- [Hello World Rust](hello-near-rust) | ||
- [Hello World JavaScript](contract-ts) | ||
- [Hello World Rust](contract-ts) | ||
- [Hello World Frontend](frontend) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "contract" | ||
name = "hello_near" | ||
version = "1.0.0" | ||
authors = ["Near Inc <[email protected]>"] | ||
edition = "2021" | ||
|
@@ -8,9 +8,12 @@ edition = "2021" | |
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
near-sdk = "4.0.0" | ||
near-sdk = "4.1.1" | ||
uint = { version = "0.9.3", default-features = false } | ||
|
||
[patch.crates-io] | ||
parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1.git' } | ||
|
||
[profile.release] | ||
codegen-units = 1 | ||
opt-level = "z" | ||
|
@@ -20,4 +23,4 @@ panic = "abort" | |
overflow-checks = true | ||
|
||
[workspace] | ||
members = [] | ||
members = ["sandbox-rs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
rustup target add wasm32-unknown-unknown | ||
cargo build --target wasm32-unknown-unknown --release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,2 @@ | ||
#!/bin/sh | ||
|
||
./build.sh | ||
|
||
echo ">> Deploying contract" | ||
|
||
near dev-deploy --wasmFile ./target/wasm32-unknown-unknown/release/contract.wasm | ||
near dev-deploy --wasmFile ./target/wasm32-unknown-unknown/release/hello_near.wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[toolchain] | ||
channel = "1.73.0" | ||
components = ["rustfmt"] | ||
targets = ["wasm32-unknown-unknown"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "sandbox" | ||
version = "1.0.0" | ||
publish = false | ||
edition = "2021" | ||
|
||
[dev-dependencies] | ||
tokio = { version = "1.18.1", features = ["full"] } | ||
near-workspaces = "0.9.0" | ||
serde_json = { version = "1.0", features = ["arbitrary_precision"] } | ||
|
||
[[example]] | ||
name = "sandbox" | ||
path = "src/tests.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use near_workspaces::{types::NearToken, Account, Contract}; | ||
use serde_json::json; | ||
use std::{env, fs}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let wasm_arg: &str = &(env::args().nth(1).unwrap()); | ||
let wasm_filepath = fs::canonicalize(env::current_dir()?.join(wasm_arg))?; | ||
|
||
let worker = near_workspaces::sandbox().await?; | ||
let wasm = std::fs::read(wasm_filepath)?; | ||
let contract = worker.dev_deploy(&wasm).await?; | ||
|
||
// create accounts | ||
let account = worker.dev_create_account().await?; | ||
let alice = account | ||
.create_subaccount("alice") | ||
.initial_balance(NearToken::from_near(30)) | ||
.transact() | ||
.await? | ||
.into_result()?; | ||
|
||
// begin tests | ||
test_default_message(&alice, &contract).await?; | ||
test_changes_message(&alice, &contract).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn test_default_message( | ||
user: &Account, | ||
contract: &Contract, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
let greeting: String = user | ||
.call(contract.id(), "get_greeting") | ||
.args_json(json!({})) | ||
.transact() | ||
.await? | ||
.json()?; | ||
|
||
assert_eq!(greeting, "Hello".to_string()); | ||
println!(" Passed ✅ gets default greeting"); | ||
Ok(()) | ||
} | ||
|
||
async fn test_changes_message( | ||
user: &Account, | ||
contract: &Contract, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
user.call(contract.id(), "set_greeting") | ||
.args_json(json!({"greeting": "Howdy"})) | ||
.transact() | ||
.await? | ||
.into_result()?; | ||
|
||
let greeting: String = user | ||
.call(contract.id(), "get_greeting") | ||
.args_json(json!({})) | ||
.transact() | ||
.await? | ||
.json()?; | ||
|
||
assert_eq!(greeting, "Howdy".to_string()); | ||
println!(" Passed ✅ changes greeting"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
# unit testing | ||
cargo test | ||
|
||
# sandbox testing | ||
./build.sh | ||
cd sandbox-rs | ||
cargo run --example sandbox "../target/wasm32-unknown-unknown/release/hello_near.wasm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "hello_near", | ||
"version": "1.0.0", | ||
"license": "(MIT AND Apache-2.0)", | ||
"engines": { | ||
"node": "16.x" | ||
}, | ||
"type": "module", | ||
"scripts": { | ||
"build": "near-sdk-js build src/contract.ts build/hello_near.wasm", | ||
"deploy": "near dev-deploy --wasmFile build/hello_near.wasm", | ||
"test": "$npm_execpath run build && cd sandbox-ts && $npm_execpath run test -- -- ../build/hello_near.wasm", | ||
"postinstall": "cd sandbox-ts && $npm_execpath install" | ||
}, | ||
"dependencies": { | ||
"near-cli": "^3.4.2", | ||
"near-sdk-js": "1.0.0" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^5.2.2", | ||
"ts-morph": "^20.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require('util').inspect.defaultOptions.depth = 5; // Increase AVA's printing depth | ||
|
||
module.exports = { | ||
timeout: '300000', | ||
files: ['src/*.ava.ts'], | ||
failWithoutAssertions: false, | ||
extensions: ['ts'], | ||
require: ['ts-node/register'], | ||
}; |
Oops, something went wrong.