-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHelloWorldTests.cs
67 lines (56 loc) · 2.31 KB
/
HelloWorldTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Meadow.Contract;
using Meadow.JsonRpc.Types;
using Meadow.UnitTestTemplate;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
namespace TokenContract
{
// Inherit from 'ContractTest' to be provided with an RpcClient,
// Accounts, and several other useful features.
[TestClass]
public class HelloWorldTests : ContractTest
{
HelloWorld _contract;
// Method is ran before each test (all tests are ran in isolation).
// This is an appropriate area to do contract deployment.
protected override async Task BeforeEach()
{
// Deploy contract.
_contract = await HelloWorld.New(RpcClient);
}
[TestMethod]
public async Task ValidateCallResult()
{
// Call the renderHelloWorld function and get the return value.
var callResult = await _contract.renderHelloWorld().Call();
// Validate the return value is what we expect.
Assert.AreEqual("Hello world", callResult);
}
[TestMethod]
public async Task ValidateSumResult()
{
// Call the renderHelloWorld function and get the return value.
var callResult = await _contract.sum(2, 4).Call();
// Validate the return value is what we expect.
Assert.AreEqual(6, callResult);
Assert.AreEqual(1, 1);
}
[TestMethod]
public async Task ValidateTransactionEventResult()
{
// Execute the renderHelloWorld function as a transaction and get the
var eventLog = await _contract.renderHelloWorld().FirstEventLog<HelloWorld.HelloEvent>();
// Validate the event log arg is what we expect.
Assert.AreEqual("Hello world", eventLog._message);
}
[TestMethod]
public async Task ValidateTransactionSender()
{
// Execute a renderHelloWorld transaction and specify the 'from' account.
var txParams = new TransactionParams { From = Accounts[5] };
var eventLog = await _contract.renderHelloWorld().FirstEventLog<HelloWorld.HelloEvent>(txParams);
// Validate the msg.sender as echoed back in our example contract.
Assert.AreEqual(eventLog._sender, Accounts[5]);
}
}
}