Skip to content

Commit

Permalink
Merge branch 'feat/next' into TOOL-360-add-token-management-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Nov 18, 2024
2 parents 1d206ec + c0a046e commit 096a825
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 36 deletions.
32 changes: 11 additions & 21 deletions src/abi/interaction.local.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { assert } from "chai";
import { promises } from "fs";
import { QueryRunnerAdapter } from "../adapters/queryRunnerAdapter";
import { SmartContractQueriesController } from "../smartContractQueriesController";
import { SmartContractTransactionsFactory } from "../smartContracts";
import { loadAbiRegistry, loadTestWallets, prepareDeployment, TestWallet } from "../testutils";
import { ContractController } from "../testutils/contractController";
import { createLocalnetProvider } from "../testutils/networkProviders";
import { Transaction } from "../transaction";
import { TransactionComputer } from "../transactionComputer";
import { TransactionsFactoryConfig } from "../transactionsFactories";
import { SmartContractTransactionsFactory } from "../transactionsFactories/smartContractTransactionsFactory";
import { TransactionWatcher } from "../transactionWatcher";
import { Interaction } from "./interaction";
import { ResultsParser } from "./resultsParser";
Expand Down Expand Up @@ -102,8 +102,7 @@ describe("test smart contract interactor", function () {

const bytecode = await promises.readFile("src/testdata/answer.wasm");

const deployTransaction = factory.createTransactionForDeploy({
sender: alice.address,
const deployTransaction = factory.createTransactionForDeploy(alice.address, {
bytecode: bytecode,
gasLimit: 3000000n,
});
Expand Down Expand Up @@ -144,8 +143,7 @@ describe("test smart contract interactor", function () {
assert.deepEqual(parsed[0], new BigNumber(42));

// Query
let transaction = factory.createTransactionForExecute({
sender: alice.address,
let transaction = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "getUltimateAnswer",
gasLimit: 3000000n,
Expand All @@ -160,8 +158,7 @@ describe("test smart contract interactor", function () {
await provider.sendTransaction(transaction);

// Execute, and wait for execution
transaction = factory.createTransactionForExecute({
sender: alice.address,
transaction = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "getUltimateAnswer",
gasLimit: 3000000n,
Expand Down Expand Up @@ -393,8 +390,7 @@ describe("test smart contract interactor", function () {

const bytecode = await promises.readFile("src/testdata/counter.wasm");

const deployTransaction = factory.createTransactionForDeploy({
sender: alice.address,
const deployTransaction = factory.createTransactionForDeploy(alice.address, {
bytecode: bytecode,
gasLimit: 3000000n,
});
Expand Down Expand Up @@ -422,8 +418,7 @@ describe("test smart contract interactor", function () {
const queryRunner = new QueryRunnerAdapter({ networkProvider: provider });
const queryController = new SmartContractQueriesController({ abi: abiRegistry, queryRunner: queryRunner });

let incrementTransaction = factory.createTransactionForExecute({
sender: alice.address,
let incrementTransaction = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "increment",
gasLimit: 3000000n,
Expand Down Expand Up @@ -451,8 +446,7 @@ describe("test smart contract interactor", function () {
let typedBundle = resultsParser.parseOutcome(transactionOnNetwork, abiRegistry.getEndpoint("increment"));
assert.deepEqual(typedBundle.firstValue!.valueOf(), new BigNumber(2));

let decrementTransaction = factory.createTransactionForExecute({
sender: alice.address,
let decrementTransaction = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "decrement",
gasLimit: 3000000n,
Expand Down Expand Up @@ -590,8 +584,7 @@ describe("test smart contract interactor", function () {
const bytecode = await promises.readFile("src/testdata/lottery-esdt.wasm");

// Deploy the contract
const deployTransaction = factory.createTransactionForDeploy({
sender: alice.address,
const deployTransaction = factory.createTransactionForDeploy(alice.address, {
bytecode: bytecode,
gasLimit: 100000000n,
});
Expand All @@ -617,8 +610,7 @@ describe("test smart contract interactor", function () {
assert.isTrue(untypedBundle.returnCode.isSuccess());

// start()
let startTransaction = factory.createTransactionForExecute({
sender: alice.address,
let startTransaction = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "start",
arguments: ["lucky", "EGLD", 1, null, null, 1, null, null],
Expand All @@ -638,8 +630,7 @@ describe("test smart contract interactor", function () {
assert.lengthOf(typedBundle.values, 0);

// status()
let lotteryStatusTransaction = factory.createTransactionForExecute({
sender: alice.address,
let lotteryStatusTransaction = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "status",
arguments: ["lucky"],
Expand All @@ -660,8 +651,7 @@ describe("test smart contract interactor", function () {
assert.equal(typedBundle.firstValue!.valueOf().name, "Running");

// getlotteryInfo() (this is a view function, but for the sake of the test, we'll execute it)
let lotteryInfoTransaction = factory.createTransactionForExecute({
sender: alice.address,
let lotteryInfoTransaction = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "getLotteryInfo",
arguments: ["lucky"],
Expand Down
14 changes: 6 additions & 8 deletions src/abi/smartContractResults.local.net.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { assert } from "chai";
import { promises } from "fs";
import { SmartContractTransactionsFactory } from "../smartContracts";
import { loadTestWallets, prepareDeployment, TestWallet } from "../testutils";
import { createLocalnetProvider } from "../testutils/networkProviders";
import { TransactionComputer } from "../transactionComputer";
import { TransactionsFactoryConfig } from "../transactionsFactories/transactionsFactoryConfig";
import { TransactionWatcher } from "../transactionWatcher";
import { ContractFunction } from "./function";
import { ResultsParser } from "./resultsParser";
import { SmartContract } from "./smartContract";
import { TransactionsFactoryConfig } from "../transactionsFactories/transactionsFactoryConfig";
import { SmartContractTransactionsFactory } from "../transactionsFactories/smartContractTransactionsFactory";
import { promises } from "fs";
import { TransactionComputer } from "../transactionComputer";

describe("fetch transactions from local testnet", function () {
let alice: TestWallet;
Expand Down Expand Up @@ -91,8 +91,7 @@ describe("fetch transactions from local testnet", function () {

const bytecode = await promises.readFile("src/testdata/counter.wasm");

const deployTransaction = factory.createTransactionForDeploy({
sender: alice.address,
const deployTransaction = factory.createTransactionForDeploy(alice.address, {
bytecode: bytecode,
gasLimit: 3000000n,
});
Expand All @@ -106,8 +105,7 @@ describe("fetch transactions from local testnet", function () {
const contractAddress = SmartContract.computeAddress(alice.address, alice.account.nonce);
alice.account.incrementNonce();

const smartContractCallTransaction = factory.createTransactionForExecute({
sender: alice.address,
const smartContractCallTransaction = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "increment",
gasLimit: 3000000n,
Expand Down
6 changes: 3 additions & 3 deletions src/smartContracts/resources.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address } from "../address";
import { TokenTransfer } from "../tokens";

export type ContractDepoyInput = {
export type ContractDeployInput = {
bytecode: Uint8Array;
gasLimit: bigint;
arguments?: any[];
Expand All @@ -12,7 +12,7 @@ export type ContractDepoyInput = {
isPayableBySmartContract?: boolean;
};

export type TransactionInput = {
export type ContractExecuteInput = {
contract: Address;
gasLimit: bigint;
function: string;
Expand All @@ -21,7 +21,7 @@ export type TransactionInput = {
tokenTransfers?: TokenTransfer[];
};

export type ContractUpgradeInput = ContractDepoyInput & { contract: Address };
export type ContractUpgradeInput = ContractDeployInput & { contract: Address };

export interface SmartContractDeployOutcome {
returnCode: string;
Expand Down
4 changes: 2 additions & 2 deletions src/smartContracts/smartContractController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SmartContractController {
async createTransactionForDeploy(
sender: IAccount,
nonce: bigint,
options: resources.ContractDepoyInput,
options: resources.ContractDeployInput,
): Promise<Transaction> {
const transaction = this.factory.createTransactionForDeploy(sender.address, options);

Expand Down Expand Up @@ -69,7 +69,7 @@ export class SmartContractController {
async createTransactionForExecute(
sender: IAccount,
nonce: bigint,
options: resources.TransactionInput,
options: resources.ContractExecuteInput,
): Promise<Transaction> {
const transaction = this.factory.createTransactionForExecute(sender.address, options);

Expand Down
4 changes: 2 additions & 2 deletions src/smartContracts/smartContractTransactionsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class SmartContractTransactionsFactory {
this.contractDeployAddress = Address.fromHex(CONTRACT_DEPLOY_ADDRESS_HEX, this.config.addressHrp);
}

createTransactionForDeploy(sender: Address, options: resources.ContractDepoyInput): Transaction {
createTransactionForDeploy(sender: Address, options: resources.ContractDeployInput): Transaction {
const nativeTransferAmount = options.nativeTransferAmount ?? 0n;
const isUpgradeable = options.isUpgradeable ?? true;
const isReadable = options.isReadable ?? true;
Expand All @@ -71,7 +71,7 @@ export class SmartContractTransactionsFactory {
}).build();
}

createTransactionForExecute(sender: Address, options: resources.TransactionInput): Transaction {
createTransactionForExecute(sender: Address, options: resources.ContractExecuteInput): Transaction {
const args = options.arguments || [];
let tokenTransfers = options.tokenTransfers ? [...options.tokenTransfers] : [];
let nativeTransferAmount = options.nativeTransferAmount ?? 0n;
Expand Down

0 comments on commit 096a825

Please sign in to comment.