const { constants } = require('@openzeppelin/test-helpers'); const { ZERO_ADDRESS } = constants; const { expect } = require("chai"); const { ethers } = require("hardhat"); describe("DocDelivery", function () { let notifications; //Tests params let _id; const _tm = 1; const _td = 700000000000; const _h = "0xb1d09af3a1f7581f4e596c87965e9536dcced8bf81636f4ec11ee521f202e9d2"; const _fc = "0xec8f82847589560cd5220e1a4acb999d50703cdced50980f7e12ed07f654da0e28554705210484a5e301c7c7b7f142f267a1637a195cfe6c161c5a6baccdf6421c"; const k = ethers.toUtf8Bytes("xjrrtwvkzyVrTAuMKvjgPbVbMyDb07w6ub4y2PtWvrwuS1vV"); beforeEach(async function () { [owner, sender, receiver] = await ethers.getSigners(); docDelivery = await ethers.getContractFactory("DocDelivery"); notifications = await docDelivery.deploy(); await notifications.waitForDeployment(); _id = ethers.keccak256(ethers.solidityPacked( ['address', 'address', 'address', 'bytes32', 'uint', 'uint'], [sender.address, receiver.address, notifications.target, _h, _tm, _td] )); }); //Once the smart contract is deployed describe('once deployed', function () { it('has owner and address', async function () { expect(notifications.runner.address).to.equal(owner.address); expect(notifications.target).to.not.equal(ZERO_ADDRESS); }); describe('undefined state', function () { it('accept from receiver allowed', async function () { const tx = await notifications.connect(receiver).accept(_id, sender.address, _h, _tm, _td, _fc); await expect(tx).to.emit(notifications, 'Result'); }); it('does not allow publish to receiver', async function () { await expect( notifications.connect(receiver).publish(_id, k) ).to.be.reverted; }); }); describe('accept state', function () { beforeEach(async function () { await notifications.connect(receiver).accept(_id, sender.address, _h, _tm, _td, _fc); }); it('does not allow accept from receiver', async function () { await expect( notifications.connect(receiver).accept(_id, sender.address, _h, _tm, _td, _fc) ).to.be.reverted; }); it('does allow publish from sender', async function () { const tx = notifications.connect(sender).publish(_id, k); await expect(tx).to.emit(notifications, 'Result'); }); }); describe('delivered state', function () { beforeEach(async function () { await notifications.connect(receiver).accept(_id, sender.address, _h, _tm, _td, _fc); await notifications.connect(sender).publish(_id, k); }); it('does not allow accept from receiver', async function () { await expect( notifications.connect(receiver).accept(_id, sender.address, _h, _tm, _td, _fc) ).to.be.reverted; }); it('does not allow publish from sender', async function () { await expect( notifications.connect(sender).publish(_id, k) ).to.be.reverted; }); }); }); });