UNPKG

thenavisapp

Version:

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

57 lines (45 loc) 1.93 kB
// SPDX-License-Identifier: MIT const { expect } = require("chai"); const MFA = artifacts.require("MFA"); contract("MFA", (accounts) => { let mfaInstance; const user1 = accounts[1]; const user2 = accounts[2]; before(async () => { mfaInstance = await MFA.deployed(); }); it("should deploy MFA contract", async () => { expect(mfaInstance.address).to.exist; }); it("should allow users to enable two-factor authentication", async () => { await mfaInstance.enableTwoFactorAuth({ from: user1 }); const isTwoFactorEnabled = await mfaInstance.isTwoFactorAuthEnabled(user1); expect(isTwoFactorEnabled).to.be.true; }); it("should not allow users to enable two-factor authentication for others", async () => { // Try to enable two-factor authentication for user2 from user1's account try { await mfaInstance.enableTwoFactorAuth({ from: user1 }); // If the above line doesn't throw an error, fail the test expect.fail("Should have thrown an error"); } catch (error) { expect(error.message).to.include("revert"); } }); it("should allow users to disable two-factor authentication", async () => { await mfaInstance.disableTwoFactorAuth({ from: user1 }); const isTwoFactorEnabled = await mfaInstance.isTwoFactorAuthEnabled(user1); expect(isTwoFactorEnabled).to.be.false; }); it("should not allow unauthorized users to disable two-factor authentication", async () => { // Try to disable two-factor authentication for user1 from user2's account try { await mfaInstance.disableTwoFactorAuth({ from: user2 }); // If the above line doesn't throw an error, fail the test expect.fail("Should have thrown an error"); } catch (error) { expect(error.message).to.include("revert"); } }); // Add more tests based on your contract's functionality });