Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-core",
"version": "15.2.2",
"version": "15.3.0",
"description": "MultiversX SDK for JavaScript and TypeScript",
"author": "MultiversX",
"homepage": "https://multiversx.com",
Expand Down
41 changes: 40 additions & 1 deletion src/smartContracts/smartContractTransactionsFactory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert } from "chai";
import { Abi, U32Value } from "../abi";
import { Abi, BigUIntValue, U32Value } from "../abi";
import { Address, Err, Token, TokenTransfer, TransactionsFactoryConfig } from "../core";
import { loadAbiRegistry, loadContractCode } from "../testutils/utils";
import { SmartContractTransactionsFactory } from "./smartContractTransactionsFactory";
Expand Down Expand Up @@ -44,6 +44,45 @@ describe("test smart contract transactions factory", function () {
}
});

it("should allow args of type 'TypedValue'", async function () {
const sender = Address.newFromBech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th");
const gasLimit = 6000000n;
const args = [new BigUIntValue(7)];

const transaction = await factory.createTransactionForDeploy(sender, {
bytecode: bytecode.valueOf(),
gasLimit: gasLimit,
arguments: args,
});

const bytecodeHex = Buffer.from(bytecode).toString("hex");
assert.deepEqual(transaction.data, Buffer.from(`${bytecodeHex}@0500@0504@07`));
});

it("should allow args of type bytes", async function () {
const sender = Address.newFromBech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th");
const gasLimit = 6000000n;
let args = [Buffer.from([7]), new Uint8Array([7])];
const bytecodeHex = Buffer.from(bytecode).toString("hex");

let transaction = await factory.createTransactionForDeploy(sender, {
bytecode: bytecode.valueOf(),
gasLimit: gasLimit,
arguments: args,
});

assert.deepEqual(transaction.data, Buffer.from(`${bytecodeHex}@0500@0504@07@07`));

args = [new Uint8Array([7]), Buffer.from("6161626261", "hex")];
transaction = await factory.createTransactionForDeploy(sender, {
bytecode: bytecode.valueOf(),
gasLimit: gasLimit,
arguments: args,
});

assert.deepEqual(transaction.data, Buffer.from(`${bytecodeHex}@0500@0504@07@6161626261`));
});

it("should create 'Transaction' for deploy", async function () {
const sender = Address.newFromBech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th");
const gasLimit = 6000000n;
Expand Down
16 changes: 15 additions & 1 deletion src/smartContracts/smartContractTransactionsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Logger } from "../core/logger";
import { TokenComputer, TokenTransfer } from "../core/tokens";
import { TokenTransfersDataBuilder } from "../core/tokenTransfersDataBuilder";
import { Transaction } from "../core/transaction";
import { byteArrayToHex, utf8ToHex } from "../core/utils.codec";
import { byteArrayToHex, utf8ToHex, zeroPadStringIfOddLength } from "../core/utils.codec";
import * as resources from "./resources";

interface IConfig {
Expand Down Expand Up @@ -226,9 +226,23 @@ export class SmartContractTransactionsFactory extends BaseFactory {
return new ArgSerializer().valuesToStrings(args);
}

if (this.areArgsBuffers(args)) {
return args.map((arg) => zeroPadStringIfOddLength(Buffer.from(arg).toString("hex")));
}

throw new Err("Can't convert args to TypedValues");
}

private areArgsBuffers(args: any[]): boolean {
for (const arg of args) {
if (!ArrayBuffer.isView(arg)) {
return false;
}
}

return true;
}

private areArgsOfTypedValue(args: any[]): boolean {
Comment thread
popenta marked this conversation as resolved.
return args.every((arg) => isTyped(arg));
}
Expand Down
Loading