From 84a40a910b45ac7d5607673bf1d877f1ab6aaba7 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Mon, 19 Mar 2018 16:31:47 -0400 Subject: [PATCH] Added tests for cancelling an audience --- contracts/communication/MessageTribute.sol | 19 +++++------- test/messageTribute.js | 36 ++++++++++++++++++++-- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/contracts/communication/MessageTribute.sol b/contracts/communication/MessageTribute.sol index 221ebf5..8acbf6e 100644 --- a/contracts/communication/MessageTribute.sol +++ b/contracts/communication/MessageTribute.sol @@ -1,6 +1,5 @@ pragma solidity ^0.4.17; -import "../common/Controlled.sol"; import "../token/MiniMeToken.sol"; @@ -13,7 +12,7 @@ import "../token/MiniMeToken.sol"; SNT is deposited, and transferred from stakeholders to recipients upon receiving a reply from the recipient. */ -contract MessageTribute is Controlled { +contract MessageTribute { MiniMeToken public SNT; @@ -23,11 +22,11 @@ contract MessageTribute is Controlled { bool permanent; } - mapping(address => mapping(address => Fee)) feeCatalog; - mapping(address => uint256) balances; + mapping(address => mapping(address => Fee)) public feeCatalog; + mapping(address => uint256) public balances; - mapping(bytes32 => uint256) friendIndex; - address[] friends; + mapping(bytes32 => uint256) private friendIndex; + address[] private friends; struct Audience { uint256 blockNum; @@ -113,8 +112,7 @@ contract MessageTribute is Controlled { balances[msg.sender] -= f.amount; } - function hasPendingAudience(address _from) - public view returns (bool) { + function hasPendingAudience(address _from) public view returns (bool) { return audienceRequested[_from][msg.sender].blockNum > 0; } @@ -126,7 +124,7 @@ contract MessageTribute is Controlled { } } - function grantAudience(address _to, bool _approve) public { + function grantAudience(address _to, bool _approve, bool refund) public { Audience memory aud = audienceRequested[msg.sender][_to]; @@ -178,7 +176,4 @@ contract MessageTribute is Controlled { feeCatalog[_from][_to].permanent = false; } } - - - } diff --git a/test/messageTribute.js b/test/messageTribute.js index 5174590..df27279 100644 --- a/test/messageTribute.js +++ b/test/messageTribute.js @@ -269,9 +269,40 @@ describe('MessageTribute', function() { "Deposited balance must be 100"); }); - it("Missing tests", async () => { - // Cancelling Audience - account8 + it("Cancelling an audience", async() => { + + assert.equal( + await MessageTribute.methods.hasPendingAudience(accounts[0]).call({from: accounts[8]}), + true, + "Must have a pending audience"); + let tx = await MessageTribute.methods.cancelAudienceRequest(accounts[0]).send({from: accounts[8]}); + + assert.notEqual(tx.events.AudienceCancelled, undefined, "AudienceCancelled wasn't triggered"); + + assert.equal( + await MessageTribute.methods.hasPendingAudience(accounts[0]).call({from: accounts[8]}), + false, + "Must not have a pending audience"); + + }); + + it("Cancelling an audience without having one", async() => { + + assert.equal( + await MessageTribute.methods.hasPendingAudience(accounts[0]).call({from: accounts[6]}), + false, + "Must not have a pending audience"); + + try { + let tx = await MessageTribute.methods.cancelAudienceRequest(accounts[0]).send({from: accounts[6]}); + assert.fail('should have reverted before'); + } catch(error) { + TestUtils.assertJump(error); + } + }); + + it("Missing tests", async () => { // Granting Audience - account7 // Deniying Audience @@ -304,6 +335,7 @@ describe('MessageTribute', function() { "Deposited balance must be 100"); // TODO grant audience + // TODO request another audience });