Skip to content
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
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
12 changes: 6 additions & 6 deletions src/abi/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Address } from "../address";
import { Compatibility } from "../compatibility";
import { TRANSACTION_VERSION_DEFAULT } from "../constants";
import { IAddress, IChainID, IGasLimit, IGasPrice, INonce, ITokenTransfer, ITransactionValue } from "../interface";
import { SmartContractTransactionsFactory } from "../smartContracts";
import { TokenTransfer } from "../tokens";
import { Transaction } from "../transaction";
import { SmartContractTransactionsFactory, TransactionsFactoryConfig } from "../transactionsFactories";
import { TransactionsFactoryConfig } from "../transactionsFactories";
import { ContractFunction } from "./function";
import { InteractionChecker } from "./interactionChecker";
import { CallArguments } from "./interface";
Expand All @@ -17,7 +18,7 @@ import { EndpointDefinition, TypedValue } from "./typesystem";
*/
interface ISmartContractWithinInteraction {
call({ func, args, value, gasLimit, receiver }: CallArguments): Transaction;
getAddress(): IAddress;
getAddress(): Address;
getEndpoint(name: ContractFunction): EndpointDefinition;
}

Expand All @@ -41,7 +42,7 @@ export class Interaction {
private chainID: IChainID = "";
private querent: IAddress = Address.empty();
private explicitReceiver?: IAddress;
private sender: IAddress = Address.empty();
private sender: Address = Address.empty();
private version: number = TRANSACTION_VERSION_DEFAULT;

private tokenTransfers: TokenTransfer[];
Expand Down Expand Up @@ -97,8 +98,7 @@ export class Interaction {
config: factoryConfig,
});

const transaction = factory.createTransactionForExecute({
sender: this.sender,
const transaction = factory.createTransactionForExecute(this.sender, {
contract: this.contract.getAddress(),
function: this.function.valueOf(),
gasLimit: BigInt(this.gasLimit.valueOf()),
Expand Down Expand Up @@ -173,7 +173,7 @@ export class Interaction {
return this;
}

withSender(sender: IAddress): Interaction {
withSender(sender: Address): Interaction {
this.sender = sender;
return this;
}
Expand Down
15 changes: 8 additions & 7 deletions src/abi/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IAddress, IChainID, IGasLimit, IGasPrice, ITransactionValue } from "../interface";
import { Address } from "../address";
import { IChainID, IGasLimit, IGasPrice, ITransactionValue } from "../interface";
import { Transaction } from "../transaction";
import { ReturnCode } from "./returnCode";
import { TypedValue } from "./typesystem";
Expand All @@ -10,7 +11,7 @@ export interface ISmartContract {
/**
* Gets the address of the Smart Contract.
*/
getAddress(): IAddress;
getAddress(): Address;

/**
* Creates a {@link Transaction} for deploying the Smart Contract to the Network.
Expand All @@ -36,7 +37,7 @@ export interface DeployArguments {
gasLimit: IGasLimit;
gasPrice?: IGasPrice;
chainID: IChainID;
deployer: IAddress;
deployer: Address;
}

export interface UpgradeArguments {
Expand All @@ -47,25 +48,25 @@ export interface UpgradeArguments {
gasLimit: IGasLimit;
gasPrice?: IGasPrice;
chainID: IChainID;
caller: IAddress;
caller: Address;
}

export interface CallArguments {
func: IContractFunction;
args?: any[];
value?: ITransactionValue;
gasLimit: IGasLimit;
receiver?: IAddress;
receiver?: Address;
gasPrice?: IGasPrice;
chainID: IChainID;
caller: IAddress;
caller: Address;
}

export interface QueryArguments {
func: IContractFunction;
args?: TypedValue[];
value?: ITransactionValue;
caller?: IAddress;
caller?: Address;
}

export interface TypedOutcomeBundle {
Expand Down
38 changes: 13 additions & 25 deletions src/abi/smartContract.local.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { promises } from "fs";
import { QueryRunnerAdapter } from "../adapters/queryRunnerAdapter";
import { Logger } from "../logger";
import { SmartContractQueriesController } from "../smartContractQueriesController";
import { SmartContractTransactionsFactory } from "../smartContracts";
import { prepareDeployment } from "../testutils";
import { createLocalnetProvider } from "../testutils/networkProviders";
import { loadTestWallets, TestWallet } from "../testutils/wallets";
import { TransactionComputer } from "../transactionComputer";
import { TransactionsFactoryConfig } from "../transactionsFactories";
import { SmartContractTransactionsFactory } from "../transactionsFactories/smartContractTransactionsFactory";
import { TransactionWatcher } from "../transactionWatcher";
import { decodeUnsignedNumber } from "./codec";
import { ContractFunction } from "./function";
Expand Down Expand Up @@ -129,8 +129,7 @@ describe("test on 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 @@ -144,8 +143,7 @@ describe("test on 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 All @@ -157,8 +155,7 @@ describe("test on local testnet", function () {

alice.account.incrementNonce();

const simulateOne = factory.createTransactionForExecute({
sender: alice.address,
const simulateOne = factory.createTransactionForExecute(alice.address, {
function: "increment",
contract: contractAddress,
gasLimit: 100000n,
Expand All @@ -171,8 +168,7 @@ describe("test on local testnet", function () {

alice.account.incrementNonce();

const simulateTwo = factory.createTransactionForExecute({
sender: alice.address,
const simulateTwo = factory.createTransactionForExecute(alice.address, {
function: "foobar",
contract: contractAddress,
gasLimit: 500000n,
Expand Down Expand Up @@ -283,8 +279,7 @@ describe("test on 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 @@ -298,8 +293,7 @@ describe("test on local testnet", function () {
const contractAddress = SmartContract.computeAddress(alice.address, alice.account.nonce);
alice.account.incrementNonce();

const firstScCallTransaction = factory.createTransactionForExecute({
sender: alice.address,
const firstScCallTransaction = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "increment",
gasLimit: 3000000n,
Expand All @@ -311,8 +305,7 @@ describe("test on local testnet", function () {

alice.account.incrementNonce();

const secondScCallTransaction = factory.createTransactionForExecute({
sender: alice.address,
const secondScCallTransaction = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "increment",
gasLimit: 3000000n,
Expand Down Expand Up @@ -449,8 +442,7 @@ describe("test on local testnet", function () {

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

const deployTransaction = factory.createTransactionForDeploy({
sender: alice.address,
const deployTransaction = factory.createTransactionForDeploy(alice.address, {
bytecode: bytecode,
gasLimit: 50000000n,
arguments: [new U32Value(10000)],
Expand All @@ -464,8 +456,7 @@ describe("test on local testnet", function () {
const contractAddress = SmartContract.computeAddress(alice.address, alice.account.nonce);
alice.account.incrementNonce();

const transactionMintBob = factory.createTransactionForExecute({
sender: alice.address,
const transactionMintBob = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "transferToken",
gasLimit: 9000000n,
Expand All @@ -478,8 +469,7 @@ describe("test on local testnet", function () {

alice.account.incrementNonce();

const transactionMintCarol = factory.createTransactionForExecute({
sender: alice.address,
const transactionMintCarol = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "transferToken",
gasLimit: 9000000n,
Expand Down Expand Up @@ -629,8 +619,7 @@ describe("test on local testnet", function () {

const bytecode = await promises.readFile("src/testdata/lottery-esdt.wasm");

const deployTransaction = factory.createTransactionForDeploy({
sender: alice.address,
const deployTransaction = factory.createTransactionForDeploy(alice.address, {
bytecode: bytecode,
gasLimit: 50000000n,
});
Expand All @@ -644,8 +633,7 @@ describe("test on local testnet", function () {
const contractAddress = SmartContract.computeAddress(alice.address, alice.account.nonce);
alice.account.incrementNonce();

const startTransaction = factory.createTransactionForExecute({
sender: alice.address,
const startTransaction = factory.createTransactionForExecute(alice.address, {
contract: contractAddress,
function: "start",
gasLimit: 10000000n,
Expand Down
Loading
Loading