const Web3 = require('web3'); const { expect } = require('chai'); const JonnyCoinContract = require('contracts/artifacts/JonnyCoin.json'); // Pfad zur ABI des Vertrags // Verbindung zur lokalen Ethereum-Testumgebung const web3 = new Web3('https://remix.ethereum.org:8545'); let accounts; let jonnyCoin; let owner; let recipient; let spender; describe('JonnyCoin Contract', () => { before(async (done) => { accounts = await web3.eth.getAccounts(); owner = accounts[0]; recipient = accounts[1]; spender = accounts[2]; // Deploy des JonnyCoin-Kontrakts jonnyCoin = await new web3.eth.Contract(JonnyCoinContract.abi) .deploy({ data: JonnyCoinContract.bytecode }) .send({ from: owner, gas: '1000000' }); done(); }); describe('Deployment', () => { it('sollte den Vertrag mit dem korrekten Namen initialisieren', async () => { const name = await jonnyCoin.methods.name().call(); expect(name).to.equal('JonnyCoin'); }); it('sollte den Vertrag mit dem korrekten Symbol initialisieren', async () => { const symbol = await jonnyCoin.methods.symbol().call(); expect(symbol).to.equal('JNC'); }); it('sollte dem Ersteller die gesamte Token-Anzahl zuweisen', async () => { const totalSupply = await jonnyCoin.methods.totalSupply().call(); const ownerBalance = await jonnyCoin.methods.balanceOf(owner).call(); expect(ownerBalance).to.equal(totalSupply); }); }); describe('Transaktionen', () => { it('sollte Token korrekt zwischen den Konten übertragen', async () => { const transferAmount = '100'; await jonnyCoin.methods.transfer(recipient, transferAmount).send({ from: owner }); const balanceRecipient = await jonnyCoin.methods.balanceOf(recipient).call(); expect(balanceRecipient).to.equal(transferAmount); }); it('sollte spender korrekt genehmigen, um eine bestimmte Anzahl von Token auszugeben', async () => { const approveAmount = '50'; await jonnyCoin.methods.approve(spender, approveAmount).send({ from: owner }); const allowance = await jonnyCoin.methods.allowance(owner, spender).call(); expect(allowance).to.equal(approveAmount); }); it('sollte transferFrom korrekt ausführen', async () => { const transferAmount = '20'; await jonnyCoin.methods.approve(spender, transferAmount).send({ from: owner }); await jonnyCoin.methods.transferFrom(owner, recipient, transferAmount).send({ from: spender }); const balanceRecipient = await jonnyCoin.methods.balanceOf(recipient).call(); expect(balanceRecipient).to.equal('120'); // 100 von vorherigem Test + 20 }); }); // Weitere Tests für Pausable, ReentrancyGuard und AddressValidator können hier hinzugefürt werden. });