Skip to content

Commit

Permalink
update test_merkle_distributor
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysg committed Dec 9, 2024
1 parent b6e3d97 commit 0660183
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions contrib-contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ serde_json = { workspace = true }
stdlib = { workspace = true }
stest = { workspace = true }
tempfile = { workspace = true }
starcoin-move-stdlib = { workspace = true }

[package]
authors = { workspace = true }
Expand Down
10 changes: 7 additions & 3 deletions contrib-contracts/src/merkle_distributor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use starcoin_vm_types::token::stc::stc_type_tag;
use starcoin_vm_types::transaction::{EntryFunction, Package, TransactionPayload};
use starcoin_vm_types::value::MoveValue;
use test_helper::executor::{
association_execute, association_execute_should_success, compile_modules_with_address,
move_abort_code, prepare_genesis,
association_execute, association_execute_should_success, compile_modules_with_address, compile_modules_with_address_internal, move_abort_code, prepare_genesis
};

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand All @@ -37,7 +36,12 @@ fn test_merkle_distributor() -> Result<()> {
// deploy the module
{
let source = include_str!("../modules/MerkleDistributor.move");
let modules = compile_modules_with_address(association_address(), source);
let mut source_files: Vec<String> = starcoin_move_stdlib::MOVE_STDLIB_SOURCE_FILES.clone();
let starcoin_stdlib_files: Vec<String> =
starcoin_move_stdlib::STARCOIN_STDLIB_SOURCE_FILES.clone();
source_files.extend(starcoin_stdlib_files);

let modules = compile_modules_with_address_internal(association_address(), source, &source_files);

let package = Package::new(modules, None)?;
association_execute_should_success(
Expand Down
9 changes: 6 additions & 3 deletions test-helper/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ pub fn get_balance<S: ChainStateReader>(address: AccountAddress, chain_state: &S
.expect("read balance resource should ok")
}

pub fn compile_modules_with_address(address: AccountAddress, code: &str) -> Vec<Module> {
info!("YSG compile_modules_with_address: {:?}", stdlib_files());
pub fn compile_modules_with_address_internal(address: AccountAddress, code: &str, libs: &Vec<String>)-> Vec<Module> {
let (_, compiled_result) =
starcoin_move_compiler::compile_source_string(code, &stdlib_files(), address)
starcoin_move_compiler::compile_source_string(code, libs, address)
.expect("compile fail");

compiled_result
Expand All @@ -121,6 +120,10 @@ pub fn compile_modules_with_address(address: AccountAddress, code: &str) -> Vec<
.collect()
}

pub fn compile_modules_with_address(address: AccountAddress, code: &str) -> Vec<Module> {
compile_modules_with_address_internal(address,code, &stdlib_files())
}

pub fn compile_script(code: impl AsRef<str>) -> Result<Vec<u8>> {
let mut compile_unit = starcoin_move_compiler::compile_source_string_no_report(
code.as_ref(),
Expand Down
2 changes: 2 additions & 0 deletions vm/framework/move-stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ move-vm-types = { workspace = true }
sha2 = "0.9.3"
sha3 = "0.9.1"
smallvec = "1.6.1"
include_dir = { workspace = true }
once_cell = { workspace = true }

[dev-dependencies]
dir-diff = "0.3.2"
Expand Down
44 changes: 44 additions & 0 deletions vm/framework/move-stdlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,48 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

use include_dir::{include_dir, Dir};
use once_cell::sync::Lazy;
pub const MOVE_STDLIB_SOURCES_DIR: Dir = include_dir!("sources");

pub static MOVE_STDLIB_SOURCE_FILES: Lazy<Vec<String>> = Lazy::new(|| {
MOVE_STDLIB_SOURCES_DIR
.files()
.iter()
.filter_map(|file| {
let ext = file.path().extension();
if let Some(ext) = ext {
if ext == "move" {
Some(file.path().display().to_string())
} else {
None
}
} else {
None
}
})
.collect()
});

pub const STARCOIN_STDLIB_SOURCES_DIR: Dir = include_dir!("../../starcoin-stdlib/sources");

pub static STARCOIN_STDLIB_SOURCE_FILES: Lazy<Vec<String>> = Lazy::new(|| {
STARCOIN_STDLIB_SOURCES_DIR
.files()
.iter()
.filter_map(|file| {
let ext = file.path().extension();
if let Some(ext) = ext {
if ext == "move" {
Some(file.path().display().to_string())
} else {
None
}
} else {
None
}
})
.collect()
});

pub mod natives;

0 comments on commit 0660183

Please sign in to comment.