Skip to content

Commit

Permalink
fix(contract): fall if descriptor file specified but not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jul 19, 2022
1 parent 278a6ff commit 37b490f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/actions/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export async function compile(filename, options) {

function getContractParams({
descrPath, contractAddress, contractSource, contractBytecode, contractAci,
}, { dummySource } = {}) {
}, { dummySource, descrMayNotExist } = {}) {
let descriptor = {};
if (descrPath && fs.existsSync(resolve(descrPath))) {
if (descrPath && (!descrMayNotExist || fs.existsSync(resolve(descrPath)))) {
descriptor = JSON.parse(readFile(resolve(descrPath)).toString());
}
return {
Expand Down Expand Up @@ -84,7 +84,7 @@ export async function deploy(walletPath, args, options) {
// source file or at location provided in descrPath. Multiple deploy of the same contract
// file will generate different deploy descriptors.
const sdk = await initSdkByWalletFile(walletPath, options);
const contract = await sdk.getContractInstance(getContractParams(options));
const contract = await sdk.getContractInstance(getContractParams(options, { descrMayNotExist: true }));
const result = await contract.deploy(args, options);
const filename = options.contractSource ?? options.contractBytecode;
options.descrPath ||= path
Expand Down
10 changes: 10 additions & 0 deletions test/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ describe('CLI Contract Module', function contractTests() {
])).to.be.rejectedWith('Invalid name or address: ct_test');
});

it('throws error if descriptor file not exists', async () => {
await expect(executeContract([
'call',
WALLET_NAME, '--password', 'test',
'--json',
'--descrPath', `${deployDescriptorFile}test`,
'test', '[1, 2]',
])).to.be.rejectedWith('ENOENT: no such file or directory, open');
});

it('calls contract static', async () => {
const callResponse = await executeContract([
'call',
Expand Down

0 comments on commit 37b490f

Please sign in to comment.