Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused interfaces (INonce, IGasLimit, IGasPrice etc.) #548

Merged
merged 1 commit into from
Dec 16, 2024
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
20 changes: 10 additions & 10 deletions src/abi/interaction.local.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ describe("test smart contract interactor", function () {
let returnEgldInteraction = <Interaction>(
contract.methods
.returns_egld_decimal([])
.withGasLimit(10000000)
.withGasLimit(10000000n)
.withChainID(network.ChainID)
.withSender(alice.address)
.withValue(1)
.withValue(1n)
);

// returnEgld()
Expand All @@ -164,10 +164,10 @@ describe("test smart contract interactor", function () {

let additionInteraction = <Interaction>contract.methods
.managed_decimal_addition([new ManagedDecimalValue("2.5", 2), new ManagedDecimalValue("2.7", 2)])
.withGasLimit(10000000)
.withGasLimit(10000000n)
.withChainID(network.ChainID)
.withSender(alice.address)
.withValue(0);
.withValue(0n);

// addition()
let additionTransaction = additionInteraction
Expand All @@ -178,10 +178,10 @@ describe("test smart contract interactor", function () {
// log
let mdLnInteraction = <Interaction>contract.methods
.managed_decimal_ln([new ManagedDecimalValue("23", 9)])
.withGasLimit(10000000)
.withGasLimit(10000000n)
.withChainID(network.ChainID)
.withSender(alice.address)
.withValue(0);
.withValue(0n);

// mdLn()
let mdLnTransaction = mdLnInteraction
Expand All @@ -194,10 +194,10 @@ describe("test smart contract interactor", function () {
new ManagedDecimalValue("4", 2, true),
new ManagedDecimalValue("5", 2, true),
])
.withGasLimit(50000000)
.withGasLimit(50000000n)
.withChainID(network.ChainID)
.withSender(alice.address)
.withValue(0);
.withValue(0n);

// addition()
let additionVarTransaction = additionVarInteraction
Expand All @@ -207,10 +207,10 @@ describe("test smart contract interactor", function () {

let lnVarInteraction = <Interaction>contract.methods
.managed_decimal_ln_var([new ManagedDecimalValue("23", 9, true)])
.withGasLimit(50000000)
.withGasLimit(50000000n)
.withChainID(network.ChainID)
.withSender(alice.address)
.withValue(0);
.withValue(0n);

// managed_decimal_ln_var()
let lnVarTransaction = lnVarInteraction
Expand Down
52 changes: 26 additions & 26 deletions src/abi/interaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ describe("test smart contract interactor", function () {

let transaction = interaction
.withSender(alice.address)
.withNonce(7)
.withValue(TokenTransfer.egldFromAmount(1))
.withGasLimit(20000000)
.withNonce(7n)
.withValue(TokenTransfer.egldFromAmount(1).amount)
popenta marked this conversation as resolved.
Show resolved Hide resolved
.withGasLimit(20000000n)
.buildTransaction();

assert.deepEqual(transaction.getReceiver(), dummyAddress);
assert.equal(transaction.getValue().toString(), "1000000000000000000");
assert.equal(transaction.getNonce(), 7);
assert.equal(transaction.getGasLimit().valueOf(), 20000000);
assert.equal(transaction.getNonce(), 7n);
assert.equal(transaction.getGasLimit().valueOf(), 20000000n);
});

it("should set transfers (payments) on contract calls (transfer and execute)", async function () {
Expand Down Expand Up @@ -181,9 +181,9 @@ describe("test smart contract interactor", function () {
.getUltimateAnswer()
.withChainID("T")
.withSender(alice)
.withGasLimit(543210)
.withGasLimit(543210n)
.withSingleESDTTransfer(new TokenTransfer({ token, amount: 100n }))
.withNonce(42)
.withNonce(42n)
.buildTransaction();

assert.deepEqual(
Expand All @@ -208,12 +208,12 @@ describe("test smart contract interactor", function () {
let contract = new SmartContract({ address: dummyAddress, abi: abiRegistry });
let controller = new SmartContractController({ chainID: "D", networkProvider: provider, abi: abiRegistry });

let interaction = <Interaction>contract.methods.getUltimateAnswer().withGasLimit(543210).withChainID("T");
let interaction = <Interaction>contract.methods.getUltimateAnswer().withGasLimit(543210n).withChainID("T");

assert.equal(contract.getAddress(), dummyAddress);
assert.deepEqual(interaction.getFunction(), new ContractFunction("getUltimateAnswer"));
assert.lengthOf(interaction.getArguments(), 0);
assert.deepEqual(interaction.getGasLimit(), 543210);
assert.deepEqual(interaction.getGasLimit(), 543210n);

provider.mockQueryContractOnFunction(
"getUltimateAnswer",
Expand All @@ -239,29 +239,29 @@ describe("test smart contract interactor", function () {
assert.deepEqual(response[0], new BigNumber(42));

// Execute, do not wait for execution
let transaction = interaction.withSender(alice.address).withNonce(0).buildTransaction();
let transaction = interaction.withSender(alice.address).withNonce(0n).buildTransaction();
transaction.setSender(alice.address);
transaction.applySignature(await alice.signer.sign(transaction.serializeForSigning()));
await provider.sendTransaction(transaction);
assert.equal(transaction.getNonce().valueOf(), 0);
assert.equal(transaction.getNonce().valueOf(), 0n);
assert.equal(transaction.getData().toString(), "getUltimateAnswer");
assert.equal(
transaction.getHash().toString(),
"3579ad09099feb9755c860ddd225251170806d833342e912fccdfe2ed5c3a364",
);

transaction = interaction.withNonce(1).buildTransaction();
transaction = interaction.withNonce(1n).buildTransaction();
transaction.setSender(alice.address);
transaction.applySignature(await alice.signer.sign(transaction.serializeForSigning()));
await provider.sendTransaction(transaction);
assert.equal(transaction.getNonce().valueOf(), 1);
assert.equal(transaction.getNonce(), 1n);
assert.equal(
transaction.getHash().toString(),
"ad513ce7c5d371d30e48f073326899766736eac1ac231d847d45bc3facbcb496",
);

// Execute, and wait for execution
transaction = interaction.withNonce(2).buildTransaction();
transaction = interaction.withNonce(2n).buildTransaction();
transaction.setSender(alice.address);
transaction.applySignature(await alice.signer.sign(transaction.serializeForSigning()));
provider.mockGetTransactionWithAnyHashAsNotarizedWithOneResult("@6f6b@2bs", "getUltimateAnswer");
Expand All @@ -281,8 +281,8 @@ describe("test smart contract interactor", function () {
let controller = new SmartContractController({ chainID: "D", networkProvider: provider, abi: abi });

let getInteraction = <Interaction>contract.methodsExplicit.get();
let incrementInteraction = (<Interaction>contract.methods.increment()).withGasLimit(543210);
let decrementInteraction = (<Interaction>contract.methods.decrement()).withGasLimit(987654);
let incrementInteraction = (<Interaction>contract.methods.increment()).withGasLimit(543210n);
let decrementInteraction = (<Interaction>contract.methods.decrement()).withGasLimit(987654n);

// For "get()", return fake 7
provider.mockQueryContractOnFunction(
Expand All @@ -308,7 +308,7 @@ describe("test smart contract interactor", function () {

let incrementTransaction = incrementInteraction
.withSender(alice.address)
.withNonce(14)
.withNonce(14n)
.withChainID("mock")
.buildTransaction();

Expand All @@ -322,19 +322,19 @@ describe("test smart contract interactor", function () {
// Decrement #1
let decrementTransaction = decrementInteraction
.withSender(alice.address)
.withNonce(15)
.withNonce(15n)
.withChainID("mock")
.buildTransaction();

decrementTransaction.applySignature(await alice.signer.sign(decrementTransaction.serializeForSigning()));
await provider.sendTransaction(decrementTransaction);
// Decrement #2
decrementTransaction = decrementInteraction.withNonce(16).buildTransaction();
decrementTransaction = decrementInteraction.withNonce(16n).buildTransaction();
decrementTransaction.applySignature(await alice.signer.sign(decrementTransaction.serializeForSigning()));
await provider.sendTransaction(decrementTransaction);
// Decrement #3

decrementTransaction = decrementInteraction.withNonce(17).buildTransaction();
decrementTransaction = decrementInteraction.withNonce(17n).buildTransaction();
decrementTransaction.applySignature(await alice.signer.sign(decrementTransaction.serializeForSigning()));
provider.mockGetTransactionWithAnyHashAsNotarizedWithOneResult("@6f6b@05", "decrement");
hash = await provider.sendTransaction(decrementTransaction);
Expand Down Expand Up @@ -362,17 +362,17 @@ describe("test smart contract interactor", function () {
OptionValue.newMissing(),
OptionalValue.newMissing(),
])
.withGasLimit(5000000)
.withGasLimit(5000000n)
);

let statusInteraction = <Interaction>contract.methods.status(["lucky"]).withGasLimit(5000000);
let statusInteraction = <Interaction>contract.methods.status(["lucky"]).withGasLimit(5000000n);

let getLotteryInfoInteraction = <Interaction>contract.methods.getLotteryInfo(["lucky"]).withGasLimit(5000000);
let getLotteryInfoInteraction = <Interaction>contract.methods.getLotteryInfo(["lucky"]).withGasLimit(5000000n);

// start()
let startTransaction = startInteraction
.withSender(alice.address)
.withNonce(14)
.withNonce(14n)
.withChainID("mock")
.buildTransaction();

Expand All @@ -392,7 +392,7 @@ describe("test smart contract interactor", function () {
// status() (this is a view function, but for the sake of the test, we'll execute it)
let statusTransaction = statusInteraction
.withSender(alice.address)
.withNonce(15)
.withNonce(15n)
.withChainID("mock")
.buildTransaction();

Expand All @@ -410,7 +410,7 @@ describe("test smart contract interactor", function () {
// lotteryInfo() (this is a view function, but for the sake of the test, we'll execute it)
let getLotteryInfoTransaction = getLotteryInfoInteraction
.withSender(alice.address)
.withNonce(15)
.withNonce(15n)
.withChainID("mock")
.buildTransaction();

Expand Down
34 changes: 17 additions & 17 deletions src/abi/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Account } from "../accounts";
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 { ITokenTransfer } from "../interface";
import { SmartContractTransactionsFactory } from "../smartContracts";
import { TokenTransfer } from "../tokens";
import { Transaction } from "../transaction";
Expand Down Expand Up @@ -34,13 +34,13 @@ export class Interaction {
private readonly function: ContractFunction;
private readonly args: TypedValue[];

private nonce: INonce = 0;
private value: ITransactionValue = "0";
private gasLimit: IGasLimit = 0;
private gasPrice: IGasPrice | undefined = undefined;
private chainID: IChainID = "";
private nonce: bigint = 0n;
private value: bigint = 0n;
private gasLimit: bigint = 0n;
private gasPrice: bigint | undefined = undefined;
private chainID: string = "";
private querent: Address = Address.empty();
private explicitReceiver?: IAddress;
private explicitReceiver?: Address;
private sender: Address = Address.empty();
private version: number = TRANSACTION_VERSION_DEFAULT;

Expand All @@ -53,7 +53,7 @@ export class Interaction {
this.tokenTransfers = [];
}

getContractAddress(): IAddress {
getContractAddress(): Address {
return this.contract.getAddress();
}

Expand All @@ -69,19 +69,19 @@ export class Interaction {
return this.args;
}

getValue(): ITransactionValue {
getValue(): bigint {
return this.value;
}

getTokenTransfers(): ITokenTransfer[] {
return this.tokenTransfers;
}

getGasLimit(): IGasLimit {
getGasLimit(): bigint {
return this.gasLimit;
}

getExplicitReceiver(): IAddress | undefined {
getExplicitReceiver(): Address | undefined {
return this.explicitReceiver;
}

Expand Down Expand Up @@ -128,7 +128,7 @@ export class Interaction {
});
}

withValue(value: ITransactionValue): Interaction {
withValue(value: bigint): Interaction {
this.value = value;
return this;
}
Expand All @@ -148,17 +148,17 @@ export class Interaction {
return this;
}

withGasLimit(gasLimit: IGasLimit): Interaction {
withGasLimit(gasLimit: bigint): Interaction {
this.gasLimit = gasLimit;
return this;
}

withGasPrice(gasPrice: IGasPrice): Interaction {
withGasPrice(gasPrice: bigint): Interaction {
this.gasPrice = gasPrice;
return this;
}

withNonce(nonce: INonce): Interaction {
withNonce(nonce: bigint): Interaction {
this.nonce = nonce;
return this;
}
Expand All @@ -167,7 +167,7 @@ export class Interaction {
return this.withNonce(account.getNonceThenIncrement());
}

withChainID(chainID: IChainID): Interaction {
withChainID(chainID: string): Interaction {
this.chainID = chainID;
return this;
}
Expand All @@ -190,7 +190,7 @@ export class Interaction {
return this;
}

withExplicitReceiver(receiver: IAddress): Interaction {
withExplicitReceiver(receiver: Address): Interaction {
this.explicitReceiver = receiver;
return this;
}
Expand Down
3 changes: 1 addition & 2 deletions src/abi/interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Address } from "../address";
import { ITransactionValue } from "../interface";
import { Transaction } from "../transaction";
import { ReturnCode } from "./returnCode";
import { TypedValue } from "./typesystem";
Expand Down Expand Up @@ -65,7 +64,7 @@ export interface CallArguments {
export interface QueryArguments {
func: IContractFunction;
args?: TypedValue[];
value?: ITransactionValue;
value?: bigint;
caller?: Address;
}

Expand Down
3 changes: 1 addition & 2 deletions src/abi/nativeSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import BigNumber from "bignumber.js";
import { Address } from "../address";
import { ErrInvalidArgument } from "../errors";
import { IAddress } from "../interface";
import { numberToPaddedHex } from "../utils.codec";
import { ArgumentErrorContext } from "./argumentErrorContext";
import {
Expand Down Expand Up @@ -67,7 +66,7 @@ import {
export namespace NativeTypes {
export type NativeBuffer = Buffer | string;
export type NativeBytes = Buffer | { valueOf(): Buffer } | string;
export type NativeAddress = string | Buffer | Address | { getAddress(): IAddress };
export type NativeAddress = string | Buffer | Address | { getAddress(): Address };
export type NativeBigNumber = BigNumber.Value | bigint;
}

Expand Down
Loading
Loading