From c596f1f246de454940bc1a4cead0244bd0cddbe4 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sun, 11 Aug 2024 15:33:00 +0700 Subject: [PATCH] Create NexusContract.test.js --- .../tests/integration/NexusContract.test.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 pi-nexus-blockchain/tests/integration/NexusContract.test.js diff --git a/pi-nexus-blockchain/tests/integration/NexusContract.test.js b/pi-nexus-blockchain/tests/integration/NexusContract.test.js new file mode 100644 index 000000000..81184f0b2 --- /dev/null +++ b/pi-nexus-blockchain/tests/integration/NexusContract.test.js @@ -0,0 +1,41 @@ +import { NexusContract } from '../../src/contracts/NexusContract'; +import Web3 from 'web3'; +import { expect } from 'chai'; + +describe('NexusContract', () => { + let web3; + let nexusContract; + + beforeEach(async () => { + web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/v3/YOUR_PROJECT_ID')); + nexusContract = new NexusContract(web3); + }); + + it('should deploy contract', async () => { + const txCount = await web3.eth.getTransactionCount(); + const deployTx = await nexusContract.deploy(); + expect(deployTx.transactionHash).to.exist; + expect(txCount + 1).to.equal(await web3.eth.getTransactionCount()); + }); + + it('should mint tokens', async () => { + const address = '0x1234567890abcdef'; + const amount = 100; + const mintTx = await nexusContract.mint(address, amount); + expect(mintTx.transactionHash).to.exist; + const balance = await nexusContract.balanceOf(address); + expect(balance).to.equal(amount); + }); + + it('should transfer tokens', async () => { + const fromAddress = '0x1234567890abcdef'; + const toAddress = '0xabcdef1234567890'; + const amount = 50; + const transferTx = await nexusContract.transfer(fromAddress, toAddress, amount); + expect(transferTx.transactionHash).to.exist; + const fromBalance = await nexusContract.balanceOf(fromAddress); + expect(fromBalance).to.equal(50); + const toBalance = await nexusContract.balanceOf(toAddress); + expect(toBalance).to.equal(amount); + }); +});