Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

created an alias method for env exported function callerHasWriteAccess #187

Merged
merged 10 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Massa-as-sdk
![check-code-coverage](https://img.shields.io/badge/coverage-70%25-orange)
![check-code-coverage](https://img.shields.io/badge/coverage-71%25-orange)




Expand Down
5 changes: 5 additions & 0 deletions assembly/std/__tests__/context.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ownedAddresses,
transactionCreator,
transferredCoins,
isDeployingContract,
} from '../context';

describe('Context', () => {
Expand Down Expand Up @@ -33,4 +34,8 @@ describe('Context', () => {
const coins = transferredCoins();
expect(coins).toBe(0);
});

test('isDeployingContract', () => {
expect(isDeployingContract()).toBe(false);
});
});
17 changes: 17 additions & 0 deletions assembly/std/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import { callerHasWriteAccess, Context } from '.';
import { env } from '../env/index';
import { Address } from './address';

/**
* Determines whether the smart contract is currently being deployed.
*
* @remarks
* This method is typically used in the constructor to ensure a one-time deployment
* and initialization, usually by the creator of the contract. Under the hood, this method
* verifies that the account calling this function (either the user creating the operation
* or an upper contract) has write access to the data of the current account
*
* @returns true if the contract is currently being deployed, false otherwise.
*/
@inline
export function isDeployingContract(): bool {
return callerHasWriteAccess() && Context.callee().notEqual(Context.caller());
}

/**
* Returns an array of addresses.
*
Expand Down
6 changes: 5 additions & 1 deletion vm-mock/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,11 @@ export default function createMockedABI(
},

assembly_script_caller_has_write_access() {
return true;
return false;
},

isDeployingContract() {
return false;
},

assembly_script_hash_sha256(aPtr) {
Expand Down