Skip to content

Commit

Permalink
Merge pull request #414 from multiversx/drop-next-prefix
Browse files Browse the repository at this point in the history
"LegacyTokenTransfer" vs. "NextTokenTransfer"
  • Loading branch information
andreibancioiu authored Mar 25, 2024
2 parents 131464d + cf0a7c1 commit 10677df
Show file tree
Hide file tree
Showing 20 changed files with 338 additions and 267 deletions.
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ export * from "./relayedTransactionV2Builder";
export * from "./signableMessage";
export * from "./smartcontracts";
export * from "./tokenOperations";
export * from "./tokenTransfer";
export * from "./tokens";
export * from "./transaction";
export * from "./transactionComputer";
export * from "./transactionPayload";
export * from "./transactionWatcher";
export * from "./utils";
export * from "./transactionComputer";
2 changes: 1 addition & 1 deletion src/proto/serializer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Address } from "../address";
import { TransactionVersion } from "../networkParams";
import { Signature } from "../signature";
import { loadTestWallets, TestWallet } from "../testutils";
import { TokenTransfer } from "../tokenTransfer";
import { TokenTransfer } from "../tokens";
import { Transaction } from "../transaction";
import { TransactionPayload } from "../transactionPayload";
import { ProtoSerializer } from "./serializer";
Expand Down
2 changes: 1 addition & 1 deletion src/relayedTransactionV1Builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as errors from "./errors";
import { TransactionOptions, TransactionVersion } from "./networkParams";
import { RelayedTransactionV1Builder } from "./relayedTransactionV1Builder";
import { TestWallet, loadTestWallets } from "./testutils";
import { TokenTransfer } from "./tokenTransfer";
import { TokenTransfer } from "./tokens";
import { Transaction } from "./transaction";
import { TransactionPayload } from "./transactionPayload";

Expand Down
2 changes: 1 addition & 1 deletion src/smartcontracts/interaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TestWallet
} from "../testutils";
import { ContractController } from "../testutils/contractController";
import { TokenTransfer } from "../tokenTransfer";
import { TokenTransfer } from "../tokens";
import { ContractFunction } from "./function";
import { Interaction } from "./interaction";
import { ReturnCode } from "./returnCode";
Expand Down
2 changes: 1 addition & 1 deletion src/smartcontracts/interactionChecker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assert } from "chai";
import { Address } from "../address";
import * as errors from "../errors";
import { loadAbiRegistry } from "../testutils";
import { TokenTransfer } from "../tokenTransfer";
import { TokenTransfer } from "../tokens";
import { Interaction } from "./interaction";
import { InteractionChecker } from "./interactionChecker";
import { SmartContract } from "./smartContract";
Expand Down
66 changes: 0 additions & 66 deletions src/tokenTransfer.spec.ts

This file was deleted.

141 changes: 0 additions & 141 deletions src/tokenTransfer.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/tokenTransferBuilders.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert } from "chai";
import { Address } from "./address";
import { TokenTransfer } from "./tokenTransfer";
import { TokenTransfer } from "./tokens";
import {
ESDTNFTTransferPayloadBuilder,
ESDTTransferPayloadBuilder,
Expand Down
2 changes: 1 addition & 1 deletion src/tokenTransferBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Address } from "./address";
import { IAddress, ITokenTransfer } from "./interface";
import { ArgSerializer } from "./smartcontracts/argSerializer";
import { AddressValue, BigUIntValue, BytesValue, TypedValue, U16Value, U64Value } from "./smartcontracts/typesystem";
import { TokenTransfer } from "./tokenTransfer";
import { TokenTransfer } from "./tokens";
import { TransactionPayload } from "./transactionPayload";

/**
Expand Down
72 changes: 68 additions & 4 deletions src/tokens.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { assert } from "chai";
import { Token, TokenComputer } from "./tokens";
import { Token, TokenComputer, TokenTransfer } from "./tokens";

describe("test token computer", async () => {
describe("test tokens and token computer", async () => {
const tokenComputer = new TokenComputer();

it("should test if token is fungible", async () => {
const fungibleToken = new Token("TEST-123456", 0n);
const nonFungibleToken = new Token("NFT-987654", 7n);
const fungibleToken = new Token({ identifier: "TEST-123456", nonce: 0n });
const nonFungibleToken = new Token({ identifier: "NFT-987654", nonce: 7n });

assert.equal(tokenComputer.isFungible(fungibleToken), true);
assert.equal(tokenComputer.isFungible(nonFungibleToken), false);
Expand All @@ -32,3 +32,67 @@ describe("test token computer", async () => {
assert.equal(identifier, "FNG-123456");
});
});

describe("test token transfer (legacy)", () => {
it("should work with EGLD", () => {
assert.equal(TokenTransfer.egldFromAmount("1").toString(), "1000000000000000000");
assert.equal(TokenTransfer.egldFromAmount("10").toString(), "10000000000000000000");
assert.equal(TokenTransfer.egldFromAmount("100").toString(), "100000000000000000000");
assert.equal(TokenTransfer.egldFromAmount("1000").toString(), "1000000000000000000000");
assert.equal(TokenTransfer.egldFromAmount("0.1").toString(), "100000000000000000");
assert.equal(TokenTransfer.egldFromAmount("0.123456789").toString(), "123456789000000000");
assert.equal(TokenTransfer.egldFromAmount("0.123456789123456789").toString(), "123456789123456789");
assert.equal(TokenTransfer.egldFromAmount("0.123456789123456789777").toString(), "123456789123456789");
assert.equal(TokenTransfer.egldFromAmount("0.123456789123456789777777888888").toString(), "123456789123456789");

assert.equal(TokenTransfer.egldFromAmount(0.1).toPrettyString(), "0.100000000000000000 EGLD");
assert.equal(TokenTransfer.egldFromAmount(1).toPrettyString(), "1.000000000000000000 EGLD");
assert.equal(TokenTransfer.egldFromAmount(10).toPrettyString(), "10.000000000000000000 EGLD");
assert.equal(TokenTransfer.egldFromAmount(100).toPrettyString(), "100.000000000000000000 EGLD");
assert.equal(TokenTransfer.egldFromAmount(1000).toPrettyString(), "1000.000000000000000000 EGLD");
assert.equal(TokenTransfer.egldFromAmount("0.123456789").toPrettyString(), "0.123456789000000000 EGLD");
assert.equal(
TokenTransfer.egldFromAmount("0.123456789123456789777777888888").toPrettyString(),
"0.123456789123456789 EGLD",
);

assert.equal(TokenTransfer.egldFromBigInteger("1").toString(), "1");
assert.equal(TokenTransfer.egldFromBigInteger("1").toPrettyString(), "0.000000000000000001 EGLD");
assert.isTrue(TokenTransfer.egldFromAmount("1").isEgld());
});

it("should work with USDC (legacy)", () => {
const identifier = "USDC-c76f1f";
const numDecimals = 6;

assert.equal(TokenTransfer.fungibleFromAmount(identifier, "1", numDecimals).toString(), "1000000");
assert.equal(TokenTransfer.fungibleFromAmount(identifier, "0.1", numDecimals).toString(), "100000");
assert.equal(TokenTransfer.fungibleFromAmount(identifier, "0.123456789", numDecimals).toString(), "123456");
assert.equal(TokenTransfer.fungibleFromBigInteger(identifier, "1000000", numDecimals).toString(), "1000000");
assert.equal(
TokenTransfer.fungibleFromBigInteger(identifier, "1000000", numDecimals).toPrettyString(),
"1.000000 USDC-c76f1f",
);
});

it("should work with MetaESDT (legacy)", () => {
const identifier = "MEXFARML-28d646";
const numDecimals = 18;
const nonce = 12345678;
const transfer = TokenTransfer.metaEsdtFromAmount(identifier, nonce, "0.1", numDecimals);

assert.equal(transfer.tokenIdentifier, identifier);
assert.equal(transfer.nonce, nonce);
assert.equal(transfer.toString(), "100000000000000000");
});

it("should work with NFTs (legacy)", () => {
const identifier = "TEST-38f249";
const nonce = 1;
const transfer = TokenTransfer.nonFungible(identifier, nonce);

assert.equal(transfer.tokenIdentifier, identifier);
assert.equal(transfer.nonce, nonce);
assert.equal(transfer.toPrettyString(), "1 TEST-38f249");
});
});
Loading

0 comments on commit 10677df

Please sign in to comment.