Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Sep 12, 2023
1 parent 9cda581 commit d4f75a0
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { assert } from "chai";
import { loadTestWallets, TestWallet } from "../testutils";
import { TokenManagementTransactionIntentsFactory } from "./tokenManagementTransactionIntentsFactory";
import { TransactionIntentsFactoryConfig } from "./transactionIntentsFactoryConfig";
import BigNumber from "bignumber.js";
import { ESDT_CONTRACT_ADDRESS } from "../constants";

describe("test token management transaction intents factory", () => {
let frank: TestWallet, grace: TestWallet;
let factory: TokenManagementTransactionIntentsFactory;
let config: TransactionIntentsFactoryConfig;

before(async function () {
({ frank, grace } = await loadTestWallets());
config = new TransactionIntentsFactoryConfig("T");
factory = new TokenManagementTransactionIntentsFactory(config);
});

it("should create transaction intent for registering and setting roles", () => {
const intent = factory.createTransactionIntentForRegisteringAndSettingRoles({
sender: frank.address,
tokenName: "TEST",
tokenTicker: "TEST",
tokenType: "FNG",
numDecimals: 2
});

assert.deepEqual(intent.data, Buffer.from("registerAndSetAllRoles@54455354@54455354@464e47@02"));
assert.equal(intent.sender, frank.address.toString());
assert.equal(intent.receiver, "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u");
assert.deepEqual(intent.value, config.issueCost);
assert.deepEqual(intent.gasLimit, new BigNumber("60125000"));
});

it("should create transaction intent for issuing fungible token", () => {
const intent = factory.createTransactionIntentForIssuingFungible({
sender: frank.address,
tokenName: "FRANK",
tokenTicker: "FRANK",
initialSupply: 100,
numDecimals: 0,
canFreeze: true,
canWipe: true,
canPause: true,
canChangeOwner: true,
canUpgrade: true,
canAddSpecialRoles: true
});

assert.deepEqual(intent.data, Buffer.from("issue@4652414e4b@4652414e4b@64@@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565"));
assert.equal(intent.sender, frank.address.toString());
assert.equal(intent.receiver, ESDT_CONTRACT_ADDRESS);
assert.deepEqual(intent.value, config.issueCost);
});

it("should create transaction intent for issuing semi-fungible token", () => {
const intent = factory.createTransactionIntentForIssuingSemiFungible({
sender: frank.address,
tokenName: "FRANK",
tokenTicker: "FRANK",
canFreeze: true,
canWipe: true,
canPause: true,
canTransferNFTCreateRole: true,
canChangeOwner: true,
canUpgrade: true,
canAddSpecialRoles: true
});

assert.deepEqual(intent.data, Buffer.from("issueSemiFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565"));
assert.equal(intent.sender, frank.address.toString());
assert.equal(intent.receiver, ESDT_CONTRACT_ADDRESS);
assert.deepEqual(intent.value, config.issueCost);
});

it("should create transaction intent for issuing non-fungible token", () => {
const intent = factory.createTransactionIntentForIssuingNonFungible({
sender: frank.address,
tokenName: "FRANK",
tokenTicker: "FRANK",
canFreeze: true,
canWipe: true,
canPause: true,
canTransferNFTCreateRole: true,
canChangeOwner: true,
canUpgrade: true,
canAddSpecialRoles: true
});

assert.deepEqual(intent.data, Buffer.from("issueNonFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565"));
assert.equal(intent.sender, frank.address.toString());
assert.equal(intent.receiver, ESDT_CONTRACT_ADDRESS);
assert.deepEqual(intent.value, config.issueCost);
});

it("should create transaction intent for registering metaEsdt", () => {
const intent = factory.createTransactionIntentForRegisteringMetaESDT({
sender: frank.address,
tokenName: "FRANK",
tokenTicker: "FRANK",
numDecimals: 10,
canFreeze: true,
canWipe: true,
canPause: true,
canTransferNFTCreateRole: true,
canChangeOwner: true,
canUpgrade: true,
canAddSpecialRoles: true
});

assert.deepEqual(intent.data, Buffer.from("registerMetaESDT@4652414e4b@4652414e4b@0a@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565"));
assert.equal(intent.sender, frank.address.toString());
assert.equal(intent.receiver, ESDT_CONTRACT_ADDRESS);
assert.deepEqual(intent.value, config.issueCost);
});

it("should create transaction intent for setting spcial role on non-fungible token", () => {
const intent = factory.createTransactionIntentForSettingSpecialRoleOnNonFungibleToken({
sender: frank.address,
user: grace.address,
tokenIdentifier: "FRANK-11ce3e",
addRoleNFTCreate: true,
addRoleNFTBurn: false,
addRoleNFTUpdateAttributes: true,
addRoleNFTAddURI: true,
addRoleESDTTransferRole: false
});

assert.deepEqual(intent.data, Buffer.from("setSpecialRole@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13@45534454526f6c654e4654437265617465@45534454526f6c654e465455706461746541747472696275746573@45534454526f6c654e4654416464555249"));
assert.equal(intent.sender, frank.address.toString());
assert.equal(intent.receiver, ESDT_CONTRACT_ADDRESS);
assert.equal(intent.value, 0);
});

it("should create transaction intent for creating nft", () => {
const intent = factory.createTransactionIntentForCreatingNFT({
sender: grace.address,
tokenIdentifier: "FRANK-aa9e8d",
initialQuantity: 1,
name: `test`,
royalties: 1000,
hash: "abba",
attributes: Buffer.from("test"),
uris: ["a", "b"]
});

assert.deepEqual(intent.data, Buffer.from("ESDTNFTCreate@4652414e4b2d616139653864@01@74657374@03e8@61626261@74657374@61@62"));
assert.equal(intent.sender, grace.address.toString());
assert.equal(intent.receiver, grace.address.toString());
assert.equal(intent.value, 0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ interface Config {
gasLimitPerByte: BigNumber.Value
gasLimitIssue: BigNumber.Value
gasLimitToggleBurnRoleGlobally: BigNumber.Value
gasLimitESDTLocalMint: BigNumber.Value
gasLimitESDTLocalBurn: BigNumber.Value
gasLimitEsdtLocalMint: BigNumber.Value
gasLimitEsdtLocalBurn: BigNumber.Value
gasLimitSetSpecialRole: BigNumber.Value
gasLimitPausing: BigNumber.Value
gasLimitFreezing: BigNumber.Value
gasLimitWiping: BigNumber.Value
gasLimitESDTNFTCreate: BigNumber.Value
gasLimitESDTNFTUpdateAttributes: BigNumber.Value
gasLimitESDTNFTAddQuantity: BigNumber.Value
gasLimitESDTNFTBurn: BigNumber.Value
gasLimitEsdtNftCreate: BigNumber.Value
gasLimitEsdtNftUpdateAttributes: BigNumber.Value
gasLimitEsdtNftAddQuantity: BigNumber.Value
gasLimitEsdtNftBurn: BigNumber.Value
gasLimitStorePerByte: BigNumber.Value
issueCost: BigNumber.Value
esdtContractAddress: IAddress
}

type RegisterAndSetAllRolesTokenType = "NFT" | "SFT" | "META" | "FNG";
Expand Down Expand Up @@ -378,7 +377,7 @@ export class TokenManagementTransactionIntentsFactory {
sender: options.sender,
receiver: options.sender,
dataParts: dataParts,
executionGasLimit: new BigNumber(this.config.gasLimitESDTNFTCreate).plus(storageGasLimit)
executionGasLimit: new BigNumber(this.config.gasLimitEsdtNftCreate).plus(storageGasLimit)
}).build();
}

Expand Down Expand Up @@ -494,7 +493,7 @@ export class TokenManagementTransactionIntentsFactory {
sender: options.sender,
receiver: options.sender,
dataParts: dataParts,
executionGasLimit: this.config.gasLimitESDTLocalMint
executionGasLimit: this.config.gasLimitEsdtLocalMint
}).build();
}

Expand All @@ -514,7 +513,7 @@ export class TokenManagementTransactionIntentsFactory {
sender: options.sender,
receiver: options.sender,
dataParts: dataParts,
executionGasLimit: this.config.gasLimitESDTLocalBurn
executionGasLimit: this.config.gasLimitEsdtLocalBurn
}).build();
}

Expand All @@ -536,7 +535,7 @@ export class TokenManagementTransactionIntentsFactory {
sender: options.sender,
receiver: options.sender,
dataParts: dataParts,
executionGasLimit: this.config.gasLimitESDTNFTUpdateAttributes
executionGasLimit: this.config.gasLimitEsdtNftUpdateAttributes
}).build();
}

Expand All @@ -558,7 +557,7 @@ export class TokenManagementTransactionIntentsFactory {
sender: options.sender,
receiver: options.sender,
dataParts: dataParts,
executionGasLimit: this.config.gasLimitESDTNFTAddQuantity
executionGasLimit: this.config.gasLimitEsdtNftAddQuantity
}).build();
}

Expand All @@ -580,7 +579,7 @@ export class TokenManagementTransactionIntentsFactory {
sender: options.sender,
receiver: options.sender,
dataParts: dataParts,
executionGasLimit: this.config.gasLimitESDTNFTBurn
executionGasLimit: this.config.gasLimitEsdtNftBurn
}).build();
}

Expand Down

0 comments on commit d4f75a0

Please sign in to comment.