public void ExecuteProposal_Success() { var duration = 10u; var contract = CreateContract(); contract.WhitelistAddress(voter); SetupMessage(proposalOwner); var proposalId = contract.CreateProposal(recipent, 100, duration, Description); SetupMessage(voter); contract.Vote(proposalId, true); SetupMessage(proposalOwner); SetupBlock(12); mContractState.Setup(m => m.GetBalance).Returns(() => 100); mTransactionExecutor.Setup(m => m.Transfer(mContractState.Object, recipent, 100)).Returns(TransferResult.Succeed()); contract.ExecuteProposal(proposalId); mTransactionExecutor.Verify(m => m.Transfer(mContractState.Object, recipent, 100), Times.Once()); contract.GetProposal(proposalId) .Executed .Should() .BeTrue(); VerifyLog(new ProposalExecutedLog { ProposalId = proposalId, Recipent = recipent, Amount = 100 }); }
public void ExecuteProposal_Transfer_Fails() { var duration = 10u; var contract = CreateContract(); contract.WhitelistAddress(voter); SetupMessage(proposalOwner); var proposalId = contract.CreateProposal(recipent, 100, duration, Description); SetupMessage(voter); contract.Vote(proposalId, true); SetupMessage(proposalOwner); SetupBlock(12); mContractState.Setup(m => m.GetBalance).Returns(() => 100); mTransactionExecutor.Setup(m => m.Transfer(mContractState.Object, recipent, 100)).Returns(TransferResult.Failed()); contract.Invoking(m => m.ExecuteProposal(proposalId)) .Should() .Throw <SmartContractAssertException>() .WithMessage("Transfer failed."); }