Skip to content

Commit 6b5f237

Browse files
authored
Merge pull request #270 from aeternity/fix-contract-call
Fix printing details of static call and improve tests
2 parents cf7a7fb + 5c119c5 commit 6b5f237

File tree

13 files changed

+841
-244
lines changed

13 files changed

+841
-244
lines changed

.mocharc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
recursive: true,
3-
timeout: '4s',
3+
timeout: '3s',
44
};

src/actions/aens.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isAddressValid, getDefaultPointerKey } from '@aeternity/aepp-sdk';
1+
import { isAddressValid, getDefaultPointerKey, isAuctionName } from '@aeternity/aepp-sdk';
22
import { initSdkByWalletFile } from '../utils/cli.js';
33
import { printTransaction } from '../utils/print.js';
44
import { getNameEntry, validateName } from '../utils/helpers.js';
@@ -127,6 +127,11 @@ export async function fullClaim(walletPath, name, options) {
127127
nameFee,
128128
});
129129

130+
if (isAuctionName(name)) {
131+
await printTransaction(nameInstance, json, aeSdk);
132+
return;
133+
}
134+
130135
nonce = nonce && nonce + 1;
131136
const updateTx = await nameInstance.update(
132137
{ account_pubkey: aeSdk.address },

src/actions/contract.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,17 @@ export async function call(fn, args, walletPath, options) {
122122
});
123123
if (json) print(callResult);
124124
else {
125-
await printTransaction(callResult.txData, json, aeSdk);
125+
await printTransaction(
126+
callStatic
127+
? { ...callResult, type: 'ContractCallTx', blockHash: 'N/A', signatures: 'N/A' }
128+
: callResult.txData,
129+
json,
130+
aeSdk,
131+
);
126132
print('----------------------Call info-----------------------');
127-
const gasCoins = BigInt(callResult.result.gasUsed) * callResult.txData.tx.gasPrice;
133+
const gasCoins =
134+
BigInt(callResult.result.gasUsed) *
135+
(callStatic ? BigInt(callResult.tx.gasPrice) : callResult.txData.tx.gasPrice);
128136
printTable([
129137
['Gas used', `${callResult.result.gasUsed} (${formatCoins(gasCoins)})`],
130138
['Return value (encoded)', callResult.result.returnValue],

src/utils/print.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { Encoding, unpackTx, AbiVersion, VmVersion } from '@aeternity/aepp-sdk';
2-
import { decode, formatCoins, formatTtl as formatTtlUnbound, formatSeconds } from './helpers.js';
2+
import {
3+
decode,
4+
formatCoins,
5+
formatTtl as formatTtlUnbound,
6+
formatSeconds,
7+
formatBlocks,
8+
} from './helpers.js';
39

410
const JsonStringifyEs = (object, spaced) =>
511
JSON.stringify(
@@ -81,10 +87,11 @@ function printTransactionSync(_tx, json, currentHeight) {
8187
txFieldRow(tx, 'Caller address', 'callerId'),
8288
// name
8389
txFieldRow(tx, 'Name ID', 'nameId'),
84-
txFieldRow(tx, 'Name TTL', 'nameTtl', formatTtl),
90+
txFieldRow(tx, 'Name TTL', 'nameTtl', formatBlocks),
8591
txFieldRow(tx, 'Name', 'name'),
8692
txFieldRow(tx, 'Name fee', 'nameFee', formatCoins),
8793
txFieldRow(tx, 'Name salt', 'nameSalt'),
94+
txFieldRow(tx, 'Name salt', 'salt'),
8895
];
8996

9097
if ('pointers' in tx) {

test/account.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import fs from 'fs-extra';
22
import { before, describe, it } from 'mocha';
3-
import { expect } from 'chai';
3+
import { expect, should } from 'chai';
44
import prompts from 'prompts';
55
import { resolve } from 'path';
66
import { getSdk, executeProgram, WALLET_NAME } from './index.js';
77
import { expectToMatchLines, toMatch } from './utils.js';
88

9+
should();
910
const executeAccount = executeProgram.bind(null, 'account');
1011
const walletName = 'test-artifacts/test-wallet.json';
1112

0 commit comments

Comments
 (0)