public void EndAuction_attempt_before_end_block_fails() { var contract = new Auction(smartContractState, 20); var exception = Assert.Throws <Exception>(() => contract.AuctionEnd()); Assert.Equal("Condition inside 'Assert' call was false.", exception.Message); }
public void EndAuction_attempt_before_end_block_fails() { var contract = new Auction(smartContractState, 20); var exception = Assert.Throws <SmartContractAssertException>(() => contract.AuctionEnd()); Assert.Equal("Assert failed.", exception.Message); }
public void EndAuction_attempt_after_end_block_succeeds() { var contract = new Auction(smartContractState, 1); var message = ((TestMessage)smartContractState.Message); message.Value = 200; message.Sender = BidderOne; contract.Bid(); smartContractState.Block.GetType().GetProperty("Number") .SetValue(smartContractState.Block, contract.EndBlock); contract.AuctionEnd(); Assert.True(contract.HasEnded); this.transactionExecutor.Received().TransferFunds(smartContractState, ContractOwnerAddress, 200ul, null); }
public void TestScenario_TwoBidders_VerifyBalances() { // Setup var auction = new Auction(SmartContractState, Duration); var bidderA = (Address)"bidderAAddress"; var bidderB = (Address)"bidderBAddress"; BlockchainBalances[ContractAddress] = 0; BlockchainBalances[ContractOwnerAddress] = 0; BlockchainBalances[bidderA] = 13; BlockchainBalances[bidderB] = 13; ulong currentSimulatedBlockNumber = ContractDeployBlockNumber; // Bidder A bids 10, is highest (and only) bid currentSimulatedBlockNumber++; SetBlock(currentSimulatedBlockNumber); MockContractMethodCall(sender: bidderA, value: 10u); auction.Bid(); // Bidder B bids 11, is new highest bid currentSimulatedBlockNumber++; SetBlock(currentSimulatedBlockNumber); MockContractMethodCall(sender: bidderB, value: 11u); auction.Bid(); // Bidder A withdraws failed bid currentSimulatedBlockNumber++; SetBlock(currentSimulatedBlockNumber); MockContractMethodCall(sender: bidderA, value: 0u); auction.Withdraw(); // Bidder A bids 12, is new highest bid currentSimulatedBlockNumber++; SetBlock(currentSimulatedBlockNumber); MockContractMethodCall(sender: bidderA, value: 12u); auction.Bid(); // AuctionEnd called by contract owner after end block has passed currentSimulatedBlockNumber = currentSimulatedBlockNumber + Duration; SetBlock(currentSimulatedBlockNumber); MockContractMethodCall(sender: ContractOwnerAddress, value: 0u); auction.AuctionEnd(); // Verify end balances var expectedBlockchainBalances = new Dictionary <Address, ulong> { { ContractAddress, 11 }, { ContractOwnerAddress, 12 }, { bidderA, 1 }, { bidderB, 2 } }; var expectedReturnBalances = new Dictionary <Address, ulong> { { bidderA, 0 }, { bidderB, 11 } }; foreach (var k in expectedBlockchainBalances.Keys) { Assert.IsTrue(BlockchainBalances[k] == expectedBlockchainBalances[k]); } foreach (var k in expectedReturnBalances.Keys) { Assert.IsTrue(auction.ReturnBalances[k] == expectedReturnBalances[k]); } // Sanity check Assert.AreEqual(SumDictionary(BlockchainBalances), SumDictionary(expectedBlockchainBalances)); }