Skip to content

Commit

Permalink
add signer reference
Browse files Browse the repository at this point in the history
  • Loading branch information
areshand authored and aptos-bot committed Apr 26, 2022
1 parent cf818a3 commit a4000ad
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
18 changes: 18 additions & 0 deletions api/src/tests/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,24 @@ async fn test_signing_message_with_script_function_payload() {
test_signing_message_with_payload(context, txn, payload).await;
}

#[tokio::test]
async fn test_execute_entry_function_with_borrowed_signer() {
let mut context = new_test_context(current_function_name!());
let account = context.gen_account();
let txn = context.create_user_account(&account);

let payload = json!({
"type": "script_function_payload",
"function": "0x1::Account::create_account",
"type_arguments": [
],
"arguments": [
account.address().to_hex_literal(), // new_account_address
]
});
test_signing_message_with_payload(context, txn, payload).await;
}

// need a correct module payload
#[ignore]
#[tokio::test]
Expand Down
10 changes: 8 additions & 2 deletions aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ impl AptosVM {
let mut signer_param_cnt = 0;
// find all signer params at the beginning
for ty in func.parameters.iter() {
if matches!(ty, Type::Signer) {
signer_param_cnt += 1;
match ty {
Type::Signer => signer_param_cnt += 1,
Type::Reference(inner_type) => {
if matches!(&**inner_type, Type::Signer) {
signer_param_cnt += 1;
}
},
_ => ()
}
}
// validate all non_signer params
Expand Down
18 changes: 9 additions & 9 deletions aptos-move/framework/aptos-framework/sources/TestCoin.move
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ module AptosFramework::TestCoin {
}

/// Claim the delegated mint capability and destroy the delegated token.
public(script) fun claim_mint_capability(account: signer) acquires Delegations {
claim_mint_capability_internal(&account);
public(script) fun claim_mint_capability(account: &signer) acquires Delegations {
claim_mint_capability_internal(account);
}

public fun claim_mint_capability_internal(account: &signer) acquires Delegations {
Expand Down Expand Up @@ -134,12 +134,12 @@ module AptosFramework::TestCoin {

/// Mint coins with capability.
public(script) fun mint(
account: signer,
account: &signer,
mint_addr: address,
amount: u64
) acquires Balance, MintCapability, CoinInfo
{
mint_internal(&account, mint_addr, amount);
mint_internal(account, mint_addr, amount);
}

public fun mint_internal(account: &signer, mint_addr: address, amount: u64) acquires Balance, MintCapability, CoinInfo {
Expand All @@ -162,8 +162,8 @@ module AptosFramework::TestCoin {
borrow_global<Balance>(owner).coin.value
}

public(script) fun transfer(from: signer, to: address, amount: u64) acquires Balance, TransferEvents {
transfer_internal(&from, to, amount);
public(script) fun transfer(from: &signer, to: address, amount: u64) acquires Balance, TransferEvents {
transfer_internal(from, to, amount);
}

/// Transfers `amount` of tokens from `from` to `to`.
Expand Down Expand Up @@ -259,7 +259,7 @@ module AptosFramework::TestCoin {
) acquires Balance, MintCapability, CoinInfo {
initialize(&account, 1000000);
let addr = Signer::address_of(&account);
mint(account, @CoreResources, 42);
mint(&account, @CoreResources, 42);
assert!(balance_of(addr) == 42, 0);
assert!(total_supply() == 42, 0);
}
Expand Down Expand Up @@ -342,7 +342,7 @@ module AptosFramework::TestCoin {
let addr1 = Signer::address_of(&receiver);
mint_internal(&account, addr, amount);

transfer(account, addr1, 400);
transfer(&account, addr1, 400);
assert!(balance_of(addr) == 600, 0);
assert!(balance_of(addr1) == 400, 0);
assert!(total_supply() == 1000, 0);
Expand All @@ -369,7 +369,7 @@ module AptosFramework::TestCoin {
initialize(&account, 1000000);
let delegatee = @0x1234;
delegate_mint_capability(account, delegatee);
claim_mint_capability(random);
claim_mint_capability(&random);
}

#[test(account = @CoreResources, random = @0x1)]
Expand Down

0 comments on commit a4000ad

Please sign in to comment.