Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Merge d42d5b0 into 3ee5ac7
Browse files Browse the repository at this point in the history
  • Loading branch information
singulared authored Mar 28, 2022
2 parents 3ee5ac7 + d42d5b0 commit e011e88
Show file tree
Hide file tree
Showing 35 changed files with 1,144 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ sp-io = { default-features = false, git = 'https://github.com/paritytech/substra
assets = { path = '../assets', default-features = false }
env_logger = "0.9.0"
test-log = "0.2.8"
move-core-types = { git = "https://github.com/pontem-network/sp-move-vm.git", rev = "c8ac6f91c7ec95e62afa3ee9ef9884eec113511c", default-features = false }
bcs = { package = "bcs", version = "0.1" }

[dependencies.move-vm]
package = "mvm"
Expand Down
42 changes: 42 additions & 0 deletions runtime/tests/assets/build_assets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Clone move-stdlib
rm -rf ./move-stdlib
git clone https://github.com/pontem-network/move-stdlib ./move-stdlib
pushd ./move-stdlib
git checkout release-v1.0.0
dove build -b
popd

# Clone pont-stdlib
rm -rf ./pont-stdlib
git clone https://github.com/pontem-network/pont-stdlib.git ./pont-stdlib
pushd ./pont-stdlib
git checkout release-v1.0.0
dove build -b
popd

pushd ./user
dove clean
dove build
dove build -b
dove tx "store_u64(42)"
dove tx "emit_event(42)"
dove tx "store_system_block()"
dove tx "store_system_timestamp()"
dove tx "inf_loop()"
dove tx "store_native_balance()"
dove tx "store_token_balance()"
dove tx "as_root(dr)"
dove tx "transfer<0x1::NOX::NOX>(Alice, 2000)" -o=transfer.mvt
dove tx "transfer<0x1::KSM::KSM>(Alice, 2000)" -o=transfer_token.mvt
dove tx "multisig_test()"
dove tx "deposit_bank<0x1::NOX::NOX>(2000)" -o=deposit_bank_pont.mvt
dove tx "deposit_bank<0x1::KSM::KSM>(2000)" -o=deposit_bank_ksm.mvt
dove tx "signer_one()" -o=signer_user.mvt
dove tx "signer_one(root)" -o=signer_root.mvt
popd

pushd ./root
dove clean
dove build
dove build -b
pushd
2 changes: 2 additions & 0 deletions runtime/tests/assets/root/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
target
14 changes: 14 additions & 0 deletions runtime/tests/assets/root/Dove.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "assets"
dialect = "pont"
dove_version = ">=1.5.5"

# account_address = "0x0" # dev/null
account_address = "0x1" # std
# account_address = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" # Alice
# account_address = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" # Bob
# account_address = "0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48" # Bob

dependencies = [
{ git = "https://github.com/pontem-network/pont-stdlib.git", rev = "e9bd26720c06705d2e222833a496fda7c67c8e32" },
]
17 changes: 17 additions & 0 deletions runtime/tests/assets/root/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "assets"
version = "0.0.1"
authors = []
dialect = "Pont"
dove_version = ">=1.5.5"

[addresses]
RootTests = "0x1"

[dependencies.PontStdlib]
git = "https://github.com/pontem-network/pont-stdlib.git"
rev = "release-v1.0.0"

[dependencies.MoveStdlib]
git = "https://github.com/pontem-network/move-stdlib.git"
rev = "release-v1.0.0"
11 changes: 11 additions & 0 deletions runtime/tests/assets/root/doc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enabled = true
section_level_start = 1
include_private_fun = true
include_specs = true
specs_inlined = true
include_impl = true
toc_depth = 3
collapsed_sections = true
root_doc_templates = []
include_dep_diagrams = false
include_call_diagrams = false
14 changes: 14 additions & 0 deletions runtime/tests/assets/root/sources/EventProxy.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module RootTests::EventProxy {
use Std::Event;

struct U64 has store, drop, copy { val: u64 }

public fun emit_event(acc: signer, val: u64) {
let event_handle = Event::new_event_handle(&acc);
Event::emit_event(
&mut event_handle,
U64 { val }
);
Event::destroy_handle(event_handle);
}
}
29 changes: 29 additions & 0 deletions runtime/tests/assets/root/sources/Store.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module RootTests::Store {
struct U64 has key { val: u64 }

struct U128 has key { val: u128 }

struct Address has key { val: address }

struct VectorU8 has key { val: vector<u8> }

public fun store_u64(account: &signer, val: u64) {
let foo = U64 { val: val };
move_to<U64>(account, foo);
}

public fun store_u128(account: &signer, val: u128) {
let foo = U128 { val: val };
move_to<U128>(account, foo);
}

public fun store_address(account: &signer, val: address) {
let addr = Address { val: val };
move_to<Address>(account, addr);
}

public fun store_vector_u8(account: &signer, val: vector<u8>) {
let vec = VectorU8 { val: val };
move_to<VectorU8>(account, vec);
}
}
2 changes: 2 additions & 0 deletions runtime/tests/assets/user/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
target
14 changes: 14 additions & 0 deletions runtime/tests/assets/user/Dove.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "assets"
dialect = "pont"
dove_version = ">=1.5.5"

# account_address = "0x0" # dev/null
# account_address = "0x1" # std
# account_address = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" # Alice
account_address = "gkNW9pAcCHxZrnoVkhLkEQtsLsW5NWTC75cdAdxAMs9LNYCYg" # Bob
# account_address = "0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48" # Bob

dependencies = [
{ git = "https://github.com/pontem-network/pont-stdlib.git", rev = "e9bd26720c06705d2e222833a496fda7c67c8e32" }
]
19 changes: 19 additions & 0 deletions runtime/tests/assets/user/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "assets"
version = "0.0.1"
authors = []
dialect = "Pont"
dove_version = ">=1.5.5"

[addresses]
UserTests = "gkNW9pAcCHxZrnoVkhLkEQtsLsW5NWTC75cdAdxAMs9LNYCYg"
Alice = "gkQ5K6EnLRgZkwozG8GiBAEnJyM6FxzbSaSmVhKJ2w8FcK7ih"
Bob = "gkNW9pAcCHxZrnoVkhLkEQtsLsW5NWTC75cdAdxAMs9LNYCYg"

[dependencies.PontStdlib]
git = "https://github.com/pontem-network/pont-stdlib.git"
rev = "release-v1.0.0"

[dependencies.MoveStdlib]
git = "https://github.com/pontem-network/move-stdlib.git"
rev = "release-v1.0.0"
11 changes: 11 additions & 0 deletions runtime/tests/assets/user/doc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enabled = true
section_level_start = 1
include_private_fun = true
include_specs = true
specs_inlined = true
include_impl = true
toc_depth = 3
collapsed_sections = true
root_doc_templates = []
include_dep_diagrams = false
include_call_diagrams = false
8 changes: 8 additions & 0 deletions runtime/tests/assets/user/scripts/AsRoot.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
script {
use Std::Signer;

fun as_root(root: signer) {
assert!(Signer::address_of(&root) == @Root, 1);
}
}

12 changes: 12 additions & 0 deletions runtime/tests/assets/user/scripts/DepositBank.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
script {
use PontemFramework::PontAccount;
use UserTests::Bank;

fun deposit_bank<TokenType: key + store>(sender: signer, amount: u64) {
// Withdraw TokenType tokens from sender account.
let tokens = PontAccount::withdraw<TokenType>(&sender, amount);

Bank::deposit(&sender, tokens);
}
}

7 changes: 7 additions & 0 deletions runtime/tests/assets/user/scripts/EmitEvent.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
script {
use UserTests::EventProxy;

fun emit_event(acc: signer, val: u64) {
EventProxy::emit_event(&acc, val);
}
}
11 changes: 11 additions & 0 deletions runtime/tests/assets/user/scripts/InfLoop.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
script {
fun inf_loop() {
let i = 0;

loop {
if (i > 1000) {
break
}
}
}
}
8 changes: 8 additions & 0 deletions runtime/tests/assets/user/scripts/MultisigTest.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
script {
use Std::Signer;

fun multisig_test(account1: signer, account2: signer) {
assert!(Signer::address_of(&account1) == @Alice, 1); // Alice
assert!(Signer::address_of(&account2) == @Bob, 1); // Bob
}
}
11 changes: 11 additions & 0 deletions runtime/tests/assets/user/scripts/NativeBalance.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
script {
use PontemFramework::PontAccount;
use PontemFramework::NOX::NOX;
use Std::Signer;
use UserTests::Store;

fun store_native_balance(account: signer) {
let balance = PontAccount::balance<NOX>(Signer::address_of(&account));
Store::store_u64(&account, balance);
}
}
5 changes: 5 additions & 0 deletions runtime/tests/assets/user/scripts/Signers.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
script {
// Just one signer required
fun signer_one(_s: signer) {
}
}
7 changes: 7 additions & 0 deletions runtime/tests/assets/user/scripts/StoreScript.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
script {
use UserTests::Store;

fun store_u64(account: signer, val: u64) {
Store::store_u64(&account, val);
}
}
8 changes: 8 additions & 0 deletions runtime/tests/assets/user/scripts/SysBlock.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
script {
use PontemFramework::PontBlock;
use UserTests::Store;

fun store_system_block(account: signer) {
Store::store_u64(&account, PontBlock::get_current_block_height());
}
}
8 changes: 8 additions & 0 deletions runtime/tests/assets/user/scripts/SysTimestamp.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
script {
use PontemFramework::PontTimestamp;
use UserTests::Store;

fun store_system_timestamp(account: signer) {
Store::store_u64(&account, PontTimestamp::now_microseconds());
}
}
11 changes: 11 additions & 0 deletions runtime/tests/assets/user/scripts/TokenBalance.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
script {
use PontemFramework::PontAccount;
use PontemFramework::KSM::KSM;
use Std::Signer;
use UserTests::Store;

fun store_token_balance(account: signer) {
let balance = PontAccount::balance<KSM>(Signer::address_of(&account));
Store::store_u64(&account, balance);
}
}
13 changes: 13 additions & 0 deletions runtime/tests/assets/user/scripts/Transfer.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
script {
use PontemFramework::PontAccount;
use Std::Signer;
use UserTests::Store;

// Transfer from Bob to Alice.
fun transfer<TokenType>(bob: signer, alice: address, to_move: u64) {
PontAccount::pay_from<TokenType>(&bob, alice, to_move);

let balance = PontAccount::balance<TokenType>(Signer::address_of(&bob));
Store::store_u64(&bob, balance);
}
}
22 changes: 22 additions & 0 deletions runtime/tests/assets/user/sources/Bank.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// Bank module (stores tokens inside module).
module UserTests::Bank {
use Std::Signer;
use PontemFramework::Token::{Self, Token};

struct Storage<phantom TokenType> has key, store {
balance: Token<TokenType>,
}

public fun deposit<TokenType>(account: &signer, deposit: Token<TokenType>) acquires Storage {
let addr = Signer::address_of(account);

if (!exists<Storage<TokenType>>(addr)) {
move_to(account, Storage {
balance: deposit
});
} else {
let storage = borrow_global_mut<Storage<TokenType>>(addr);
Token::deposit<TokenType>(&mut storage.balance, deposit);
}
}
}
16 changes: 16 additions & 0 deletions runtime/tests/assets/user/sources/EventProxy.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module UserTests::EventProxy {
use Std::Event;

struct U64 has store, drop, copy { val: u64 }

public fun emit_event(acc: &signer, val: u64) {
let event_handle = Event::new_event_handle(acc);

Event::emit_event(
&mut event_handle,
U64 { val }
);

Event::destroy_handle(event_handle);
}
}
Loading

0 comments on commit e011e88

Please sign in to comment.