/ test / governance / ProtocolSettings / testCastVote.t.sol
testCastVote.t.sol
 1  pragma solidity >=0.6.0;
 2  
 3  import "truffle/Assert.sol";
 4  import "./Base.t.sol";
 5  
 6  contract TestCastVote is Base {
 7  
 8      function testCastVoteForApproval() public {
 9          
10          ChangeInterestRateProposal p = new ChangeInterestRateProposal();
11          
12          uint newInterestRate     = 10000000098397720;
13          uint newInterestRateBase = 10000000000000002;
14          p.setInterestRate(newInterestRate, newInterestRateBase);
15  
16          (,ProposalWrapper w) = alpha.registerProposal(p, SIMPLE_MAJORITY, now + 10 days);
17  
18          alpha.castVote(w, true);
19          beta.castVote(w, true);
20          gama.castVote(w, false);
21  
22          (uint ir1, uint b1,) = settings.getDebtInterestRate();
23  
24          (bool success,) = address(w).call(
25              abi.encodePacked(
26                  w.close.selector
27              )
28          );
29          
30          Assert.isTrue(w.getStatus() == ProposalWrapper.Status.APPROVED, "proposal APPROVED");
31  
32          (uint ir2, uint b2,) = settings.getDebtInterestRate();
33          Assert.notEqual(ir1, ir2, "old interest rate");
34          Assert.notEqual(b1, b2, "old interest rate base");
35          Assert.equal(ir2, newInterestRate, "new interest rate");
36          Assert.equal(b2, newInterestRateBase, "new interest rate base");
37      }
38  
39      function testCastVoteForRejection() public {
40          
41          ChangeInterestRateProposal p = new ChangeInterestRateProposal();
42          
43          uint newInterestRate     = 10000000088884444;
44          uint newInterestRateBase = 10000000000000003;
45          p.setInterestRate(newInterestRate, newInterestRateBase);
46  
47          (,ProposalWrapper w) = alpha.registerProposal(p, SIMPLE_MAJORITY, now + 10 days);
48  
49          alpha.castVote(w, true);
50          beta.castVote(w, false);
51          gama.castVote(w, false);
52  
53          (uint ir1, uint b1,) = settings.getDebtInterestRate();
54  
55          w.close();
56          
57          Assert.isTrue(w.getStatus() == ProposalWrapper.Status.REJECTED, "proposal REJECTED");
58  
59          (uint ir2, uint b2,) = settings.getDebtInterestRate();
60          Assert.equal(ir1, ir2, "old interest rate");
61          Assert.equal(b1, b2, "old interest rate base");
62          Assert.notEqual(ir2, newInterestRate, "new interest rate");
63          Assert.notEqual(b2, newInterestRateBase, "new interest rate base");
64      }
65  }