[InlineData(uint.MaxValue, 0)] // uint.MaxValue should overflow public void SendPing_Opponent_Not_Finished_Success(uint initialPingsSent, uint expectedPingsSent) { var player = this.NewPlayer(); this.mockContractState.Setup(s => s.Message.Sender).Returns(PlayerAddress); this.mockPersistentState.Setup(s => s.GetUInt32(nameof(Player.State))).Returns((uint)Player.StateType.ReceivedPing); this.mockPersistentState.Setup(s => s.GetUInt32(nameof(Player.PingsSent))).Returns(initialPingsSent); // Return false this.mockInternalExecutor.Setup(s => s.Call( It.IsAny <ISmartContractState>(), It.IsAny <Address>(), It.IsAny <ulong>(), nameof(Player.IsFinished), It.IsAny <object[]>(), It.IsAny <ulong>())) .Returns(TransferResult.Transferred(false)); this.mockInternalExecutor.Setup(s => s.Call( It.IsAny <ISmartContractState>(), It.IsAny <Address>(), It.IsAny <ulong>(), nameof(Player.ReceivePing), It.IsAny <object[]>(), It.IsAny <ulong>())) .Returns(TransferResult.Empty()); player.SendPing(); this.mockInternalExecutor.Verify(s => s.Call(this.mockContractState.Object, OpponentAddress, 0, nameof(Player.IsFinished), null, 0)); this.mockInternalExecutor.Verify(s => s.Call(this.mockContractState.Object, OpponentAddress, 0, nameof(Player.ReceivePing), null, 0)); this.mockPersistentState.Verify(s => s.SetUInt32(nameof(Player.PingsSent), expectedPingsSent), Times.Once); this.mockPersistentState.Verify(s => s.SetUInt32(nameof(Player.State), (uint)Player.StateType.SentPing), Times.Once); }
public void BuyItem_Succeeds() { var seller = PartyA; var buyer = PartyB; var itemPrice = 1UL; // Setup the expected state values. this.mockPersistentState.Setup(s => s.GetUInt64(nameof(ItemListing.ItemPrice))).Returns(itemPrice); this.mockPersistentState.Setup(s => s.GetAddress(nameof(ItemListing.Seller))).Returns(seller); this.mockPersistentState.Setup(s => s.GetAddress(nameof(ItemListing.ParentContract))).Returns(ParentContract); this.mockContractState.Setup(s => s.Message.Sender).Returns(ParentContract); var itemListing = new ItemListing(this.mockContractState.Object, "Test", itemPrice, seller, ParentContract, PartyA, PartyB); // HasBalance returns true. this.mockInternalExecutor .Setup(c => c.Call( It.IsAny <ISmartContractState>(), It.IsAny <Address>(), It.IsAny <ulong>(), nameof(Bazaar.HasBalance), It.IsAny <object[]>(), It.IsAny <ulong>())) .Returns(TransferResult.Transferred(true)); // UpdateBalance is successful. this.mockInternalExecutor .Setup(c => c.Call( It.IsAny <ISmartContractState>(), It.IsAny <Address>(), It.IsAny <ulong>(), nameof(Bazaar.UpdateBalance), It.IsAny <object[]>(), It.IsAny <ulong>())) .Returns(TransferResult.Empty()); this.mockContractState.Setup(s => s.Message.Sender).Returns(buyer); itemListing.BuyItem(); this.mockInternalExecutor .Verify( c => c.Call( It.IsAny <ISmartContractState>(), ParentContract, 0, nameof(Bazaar.HasBalance), It.Is <object[]>(o => (Address)o[0] == buyer && (ulong)o[1] == itemPrice), 0), Times.Once); this.mockInternalExecutor .Verify( c => c.Call( It.IsAny <ISmartContractState>(), ParentContract, 0, nameof(Bazaar.UpdateBalance), It.Is <object[]>(o => (Address)o[0] == seller && (Address)o[1] == buyer && (ulong)o[2] == itemPrice), 0), Times.Once); this.mockPersistentState.Verify(s => s.SetUInt32(nameof(Bazaar.State), (uint)ItemListing.StateType.ItemSold)); }