/ test / governance / ProtocolSettings / testCloseProposal.t.sol
testCloseProposal.t.sol
  1  pragma solidity >=0.6.0;
  2  
  3  import "truffle/Assert.sol";
  4  import "./Base.t.sol";
  5  
  6  contract TestCloseProposal is Base {
  7  
  8      function testCloseProposalBeforeQuorum() public {
  9          
 10          ChangeInterestRateProposal p = new ChangeInterestRateProposal();
 11          
 12          uint newInterestRate     = 10000000098765432;
 13          uint newInterestRateBase = 10000000000000001;
 14          p.setInterestRate(newInterestRate, newInterestRateBase);
 15  
 16          (,ProposalWrapper w) = alpha.registerProposal(p, SIMPLE_MAJORITY, now + 10 days);
 17              
 18          (bool success,) = address(w).call(
 19              abi.encodePacked(
 20                  w.close.selector
 21              )
 22          );
 23          
 24          Assert.isFalse(success, "close should fail");
 25      }
 26  
 27      function testCloseProposalThenTransferSmallAmountOfGovTokens() public {
 28          
 29          ChangeInterestRateProposal p = new ChangeInterestRateProposal();
 30          
 31          uint newInterestRate     = 10000000012345678;
 32          uint newInterestRateBase = 10000000000000004;
 33          p.setInterestRate(newInterestRate, newInterestRateBase);
 34  
 35          (,ProposalWrapper w) = alpha.registerProposal(p, SIMPLE_MAJORITY, now + 10 days);
 36  
 37          alpha.castVote(w, true);
 38          beta.castVote(w, false);
 39          gama.castVote(w, false);
 40  
 41          gama.transfer(address(alpha), 5 finney); // 0.5%
 42  
 43          (uint ir1, uint b1,) = settings.getDebtInterestRate();
 44  
 45          w.close();
 46          
 47          Assert.isTrue(w.getStatus() == ProposalWrapper.Status.REJECTED, "proposal REJECTED");
 48  
 49          (uint ir2, uint b2,) = settings.getDebtInterestRate();
 50          Assert.equal(ir1, ir2, "old interest rate");
 51          Assert.equal(b1, b2, "old interest rate base");
 52      }
 53  
 54      function testCloseProposalThenTransferLargerAmountOfGovTokens() public {
 55          
 56          ChangeInterestRateProposal p = new ChangeInterestRateProposal();
 57          
 58          uint newInterestRate     = 10000000012345678;
 59          uint newInterestRateBase = 10000000000000004;
 60          p.setInterestRate(newInterestRate, newInterestRateBase);
 61  
 62          (,ProposalWrapper w) = alpha.registerProposal(p, SIMPLE_MAJORITY, now + 10 days);
 63  
 64          alpha.castVote(w, true);
 65          beta.castVote(w, false);
 66          gama.castVote(w, false);
 67  
 68          gama.transfer(address(alpha), 10 finney); // 1%
 69  
 70          (uint ir1, uint b1,) = settings.getDebtInterestRate();
 71  
 72          (bool success,) = address(w).call(
 73              abi.encodePacked(
 74                  w.close.selector
 75              )
 76          );
 77          
 78          Assert.isTrue(w.getStatus() == ProposalWrapper.Status.APPROVED, "proposal APPROVED");
 79  
 80          (uint ir2, uint b2,) = settings.getDebtInterestRate();
 81          Assert.notEqual(ir1, ir2, "old interest rate");
 82          Assert.notEqual(b1, b2, "old interest rate base");
 83          Assert.equal(ir2, newInterestRate, "new interest rate");
 84          Assert.equal(b2, newInterestRateBase, "new interest rate base");
 85      }
 86  
 87      function testCloseProposalWhenHotVotingIsNotAllowed() public {
 88          
 89          ChangeInterestRateProposal p = new ChangeInterestRateProposal();
 90          
 91          uint newInterestRate     = 10000000012345678;
 92          uint newInterestRateBase = 10000000000000004;
 93          p.setInterestRate(newInterestRate, newInterestRateBase);
 94  
 95          (,ProposalWrapper w) = alpha.registerProposal(p, SIMPLE_MAJORITY, now + 10 days);
 96  
 97          alpha.castVote(w, true);
 98          beta.castVote(w, false);
 99          gama.castVote(w, false);
100  
101          gama.transfer(address(alpha), 10 finney); // 1%
102  
103          settings.suppressHotVoting();
104  
105          (bool success,) = address(w).call(
106              abi.encodePacked(
107                  w.close.selector
108              )
109          );
110          
111          Assert.isFalse(success, "close should fail");
112      }
113  }