Skip to content

Commit

Permalink
Merge remote-tracking branch origin/rc/v0.53 into keystore-pem-conver…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
andreivasilescu24 committed Aug 21, 2024
2 parents 1d897df + db6da05 commit 1f16dd3
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ main = "rust-testing-framework-tester"
# the only purpose of this config is to specify the allocator
[contracts.rust-testing-framework-tester]
allocator = "static64k"

[[proxy]]
path = "src/rust_testing_framework_tester_proxy.rs"
add-unlabelled = false
add-endpoints = ["init"]
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
multiversx_sc::imports!();

#[multiversx_sc::module]
pub trait DummyModule {
fn some_function(&self) -> BigUint {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#![no_std]

multiversx_sc::imports!();
multiversx_sc::derive_imports!();
use multiversx_sc::proxy_imports::*;

pub mod dummy_module;
pub mod rust_testing_framework_tester_proxy;

#[derive(TopEncode, TopDecode, TypeAbi, Clone, Debug, PartialEq, Eq)]
#[type_abi]
#[derive(TopEncode, TopDecode, Clone, Debug, PartialEq, Eq)]
pub struct NftDummyAttributes {
pub creation_epoch: u64,
pub cool_factor: u8,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT.

////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
////////////////////////////////////////////////////

#![allow(dead_code)]
#![allow(clippy::all)]

use multiversx_sc::proxy_imports::*;

pub struct RustTestingFrameworkTesterProxy;

impl<Env, From, To, Gas> TxProxyTrait<Env, From, To, Gas> for RustTestingFrameworkTesterProxy
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
type TxProxyMethods = RustTestingFrameworkTesterProxyMethods<Env, From, To, Gas>;

fn proxy_methods(self, tx: Tx<Env, From, To, (), Gas, (), ()>) -> Self::TxProxyMethods {
RustTestingFrameworkTesterProxyMethods { wrapped_tx: tx }
}
}

pub struct RustTestingFrameworkTesterProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
wrapped_tx: Tx<Env, From, To, (), Gas, (), ()>,
}

#[rustfmt::skip]
impl<Env, From, Gas> RustTestingFrameworkTesterProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn init(
self,
) -> TxTypedDeploy<Env, From, NotPayable, Gas, ManagedBuffer<Env::Api>> {
self.wrapped_tx
.payment(NotPayable)
.raw_deploy()
.original_result()
}
}

#[type_abi]
#[derive(TopEncode, TopDecode, Clone, Debug, PartialEq, Eq)]
pub struct NftDummyAttributes {
pub creation_epoch: u64,
pub cool_factor: u8,
}
Original file line number Diff line number Diff line change
@@ -1,77 +1,50 @@
use multiversx_sc_scenario::imports::*;
use rust_testing_framework_tester::*;

const WASM_PATH_EXPR: &str = "mxsc:output/rust-testing-framework-tester.mxsc.json";
const CODE_PATH: MxscPath = MxscPath::new("output/rust-testing-framework-tester.mxsc.json");
const OWNER_ADDRESS: TestAddress = TestAddress::new("owner");
const RUST_TESTING_FRAMEWORK_TESTER_ADDRESS: TestSCAddress =
TestSCAddress::new("rust-testing-framework-tester");

fn world() -> ScenarioWorld {
let mut blockchain = ScenarioWorld::new();
blockchain.register_contract(
WASM_PATH_EXPR,
rust_testing_framework_tester::ContractBuilder,
);
blockchain.register_contract(CODE_PATH, rust_testing_framework_tester::ContractBuilder);

blockchain
}

#[test]
#[allow(deprecated)]
fn tester_deploy_test() {
let mut world = world();
let code = world.code_expression(WASM_PATH_EXPR);

let owner_address = "address:owner";
let mut adder_contract =
ContractInfo::<rust_testing_framework_tester::Proxy<StaticApi>>::new("sc:contract");
world.start_trace();

world.account(OWNER_ADDRESS).new_address(
OWNER_ADDRESS,
0,
RUST_TESTING_FRAMEWORK_TESTER_ADDRESS,
);

world
.start_trace()
.set_state_step(
SetStateStep::new()
.put_account(owner_address, Account::new())
.new_address(owner_address, 0, &adder_contract),
)
.sc_deploy_use_result(
ScDeployStep::new()
.from(owner_address)
.code(code)
.call(adder_contract.init()),
|address, tr: TypedResponse<String>| {
assert_eq!(address, adder_contract.to_address());
assert_eq!(tr.result.unwrap(), "constructor-result");
},
)
.write_scenario_trace("scenarios/trace-deploy.scen.json");
let (returned_value, contract_address) = world
.tx()
.from(OWNER_ADDRESS)
.typed(rust_testing_framework_tester_proxy::RustTestingFrameworkTesterProxy)
.init()
.code(CODE_PATH)
.returns(ReturnsResult)
.new_address(RUST_TESTING_FRAMEWORK_TESTER_ADDRESS)
.returns(ReturnsNewAddress)
.run();

assert_eq!(returned_value.to_string(), "constructor-result");
assert_eq!(contract_address, RUST_TESTING_FRAMEWORK_TESTER_ADDRESS);

world.write_scenario_trace("scenarios/trace-deploy.scen.json");
}

#[test]
#[allow(deprecated)]
fn tester_deploy_test_spawned_thread() {
let handler = std::thread::spawn(|| {
let mut world = world();
let code = world.code_expression(WASM_PATH_EXPR);

let owner_address = "address:owner";
let mut adder_contract =
ContractInfo::<rust_testing_framework_tester::Proxy<StaticApi>>::new("sc:contract");

world
.start_trace()
.set_state_step(
SetStateStep::new()
.put_account(owner_address, Account::new())
.new_address(owner_address, 0, &adder_contract),
)
.sc_deploy_use_result(
ScDeployStep::new()
.from(owner_address)
.code(code)
.call(adder_contract.init()),
|address, tr: TypedResponse<String>| {
assert_eq!(address, adder_contract.to_address());
assert_eq!(tr.result.unwrap(), "constructor-result");
},
)
.write_scenario_trace("scenarios/trace-deploy.scen.json");
});
let handler = std::thread::spawn(tester_deploy_test);

handler.join().unwrap();
}
1 change: 1 addition & 0 deletions framework/meta/src/cmd/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn wallet(args: &WalletArgs) {
WalletAction::Convert(convert_args) => convert(convert_args),
}
}

fn convert(convert_args: &WalletConvertArgs) {
let infile = convert_args.infile.as_ref();
let outfile = convert_args.outfile.as_ref();
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl Wallet {

let mut digest =
HmacSha512::new_from_slice(b"ed25519 seed").expect("HMAC can take key of any size");
HmacSha512::new_from_slice(b"ed25519 seed").expect("HMAC can take key of any size");
digest.update(&seed);
let intermediary: Vec<u8> = digest.finalize().into_bytes().into_iter().collect();
let mut key = intermediary[..serialized_key_len].to_vec();
Expand All @@ -100,6 +101,7 @@ impl Wallet {

digest =
HmacSha512::new_from_slice(&chain_code).expect("HMAC can take key of any size");
HmacSha512::new_from_slice(&chain_code).expect("HMAC can take key of any size");
digest.update(&buff);
let intermediary: Vec<u8> = digest.finalize().into_bytes().into_iter().collect();
key = intermediary[..serialized_key_len].to_vec();
Expand Down

0 comments on commit 1f16dd3

Please sign in to comment.