Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

scan token test js

// ethers is global variable here.

const { expect } = require("chai");
const { expectRevert } = require('@openzeppelin/test-helpers');

// 1.
const totalSupplyBigNumberHex = ethers.BigNumber.from("0x52b7d2dcc80cd2e4000000");
const preMineBigNumberHex = ethers.BigNumber.from("0x108b2a2c28029094000000");
const airDropSize = "1000000000000000000000000"; // "0xD3C21BCECCEDA1000000"

describe("SCAMToken state and transactions", function () {
  let SCAMToken, scamToken, owner, firstComer, secondComer; // seller is owner

  // We don't include events here 
  // because it was already handled in the previous post
  beforeEach(async () => {
    provider = ethers.getDefaultProvider();

    SCAMToken = await ethers.getContractFactory("SCAM_Token");
    scamToken = await SCAMToken.deploy();

    [owner, firstComer, secondComer, _] = await ethers.getSigners();
  });

  it("Should test 'totalSupply' and other default values.", async function () {
    // 2.
    expect(await scamToken.symbol()).to.equal("SCAM");
    expect(await scamToken.name()).to.equal("Safe Crypto And Money");
    expect(await scamToken.decimals()).to.equal(18);

    const totalSupply = await scamToken.totalSupply();
    expect(totalSupply).to.equal(totalSupplyBigNumberHex);

    // What the owner takes from the total supply
    const preMine = await scamToken.balanceOf(owner.address);
    expect(preMine).to.equal(preMineBigNumberHex);
  });

  it("Should test 'airdropTokens' and the contract and receiver balance change.", async function () {
    // 3.
    await expectRevert.unspecified(scamToken.connect(firstComer).airdropTokens(firstComer.address));
    await expectRevert.unspecified(scamToken.connect(secondComer).airdropTokens(secondComer.address));

    // From contract to a user
    await scamToken.airdropTokens(firstComer.address);
    // Include contract balance also here.
    const firstComerBalance = await scamToken.balanceOf(firstComer.address);
    expect(firstComerBalance.toString()).to.equal(airDropSize);
  });

  // 4.
  it("Should test 'transfer' from the owner to firstComer.", async function () {
    // From a user to another user
    const amountToTransfer = 1000000;
    await scamToken.transfer(firstComer.address, amountToTransfer);

    let firstComerBalance = await scamToken.balanceOf(firstComer.address);
    expect(firstComerBalance.toString()).to.equal(amountToTransfer.toString());
  });

  it("Should test 'approve' and 'allowance' from the owner to firstComer.", async function () {
    const amountForApproval = 1000000;
    await scamToken.approve(firstComer.address, amountForApproval);

    const allowance = await scamToken.allowance(owner.address, firstComer.address);
    expect(allowance.toString()).to.equal(amountForApproval.toString());
  });

  it("Should test 'approve', 'allowance' and 'transferFrom'.", async function () {
    const amountForApproval = 1000000;
    await scamToken.approve(firstComer.address, amountForApproval);
    const allowance = await scamToken.allowance(owner.address, firstComer.address);
    expect(allowance.toString()).to.equal(amountForApproval.toString());

    await scamToken.connect(firstComer).transferFrom(owner.address, secondComer.address, amountForApproval);

    const secondComerBalance = await scamToken.balanceOf(secondComer.address);
    expect(secondComerBalance.toString()).to.equal(amountForApproval.toString());
  });

  // 5.
  it("Should test 'releaseBNB' and it shouldn't affect the balance of other users (not owners)", async function () {
    const amountForApproval = 1000000;
    await scamToken.approve(firstComer.address, amountForApproval);
    const allowance = await scamToken.allowance(owner.address, firstComer.address);
    expect(allowance.toString()).to.equal(amountForApproval.toString());

    await scamToken.connect(firstComer).transferFrom(owner.address, secondComer.address, amountForApproval);

    const secondComerBalance = await scamToken.balanceOf(secondComer.address);
    expect(secondComerBalance.toString()).to.equal(amountForApproval.toString());

    await scamToken.releaseBNB();
    expect(secondComerBalance.toString()).to.equal(amountForApproval.toString());
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: when end sound show alert 
Javascript :: white for file loaded 
Javascript :: js undici fetch data async 
Javascript :: hook use effect with class 
Javascript :: using lambda for elasticache node.js 
Javascript :: javascript search an array of json for matching attribute 
Javascript :: store reference of event listener inside a element 
Javascript :: spiral traversal clockwise direction js 
Javascript :: enum jpa jsf jakarta9 
Javascript :: js replay animation 
Javascript :: jquery selectors 
Javascript :: what does the ... mean in javascript 
Javascript :: js promise example 
Javascript :: javascript brightness filter 
Javascript :: add google map in react js 
Javascript :: change value in array react 
Javascript :: switch case 
Javascript :: random number between 1 and 10 javascript 
Javascript :: for loop in js 
Javascript :: array and array compare 
Javascript :: create slice redux 
Javascript :: objects in array 
Javascript :: autofocus is not working in react native 
Javascript :: print a number with commas as thousands separator 
Javascript :: mongoose find by nested property 
Javascript :: loop for of 
Javascript :: serializes to the same string 
Javascript :: how to hack facebook 
Javascript :: regex javascript matching first letter to last 
Javascript :: set methods in js 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =