-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathNativeArtifactsTests.cs
98 lines (72 loc) · 3.05 KB
/
NativeArtifactsTests.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using System.Numerics;
using System.Reflection;
namespace Neo.SmartContract.Testing.UnitTests
{
[TestClass]
public class NativeArtifactsTests
{
[TestMethod]
public void TestInitialize()
{
var engine = new TestEngine();
Assert.AreEqual(0, engine.Storage.Store.Seek(System.Array.Empty<byte>(), Persistence.SeekDirection.Forward).Count());
engine.Native.Initialize(true);
// Ensure that the main address contains the totalSupply
Assert.AreEqual(100_000_000, engine.Native.NEO.totalSupply());
Assert.AreEqual(engine.Native.NEO.totalSupply(), engine.Native.NEO.balanceOf(engine.BFTAddress));
}
[TestMethod]
public void TestTransfer()
{
var engine = new TestEngine(true);
engine.Storage.Commit(); // Bug in MemoryStore
// Test set
Assert.AreEqual(500000000, engine.Native.NEO.getGasPerBlock());
// Fake signature
engine.Transaction.Signers = new Network.P2P.Payloads.Signer[]
{
new Network.P2P.Payloads.Signer()
{
Account = engine.BFTAddress,
Scopes = Network.P2P.Payloads.WitnessScope.Global
}
};
bool raisedEvent = false;
engine.Native.NEO.Transfer += (UInt160 from, UInt160 to, BigInteger amount) =>
{
raisedEvent = true;
};
UInt160 wallet = UInt160.Parse("0x1230000000000000000000000000000000000000");
Assert.AreEqual(0, engine.Native.NEO.balanceOf(wallet));
Assert.IsTrue(engine.Native.NEO.transfer(engine.Transaction.Sender, wallet, 123, null));
Assert.IsTrue(raisedEvent);
engine.Storage.Commit(); // Bug in MemoryStore
Assert.AreEqual(123, engine.Native.NEO.balanceOf(wallet));
}
[TestMethod]
public void TestSignature()
{
var engine = new TestEngine(true);
engine.Storage.Commit(); // Bug in MemoryStore
// Test set
Assert.AreEqual(100000000000, engine.Native.NEO.getRegisterPrice());
// Fake signature
engine.Transaction.Signers = new Network.P2P.Payloads.Signer[]
{
new Network.P2P.Payloads.Signer()
{
Account = engine.Native.GetCommitteeAddress(),
Scopes = Network.P2P.Payloads.WitnessScope.Global
}
};
engine.Native.NEO.setRegisterPrice(123);
engine.Storage.Commit(); // Bug in MemoryStore
Assert.AreEqual(123, engine.Native.NEO.getRegisterPrice());
// Invalid signature
engine.Transaction.Signers[0].Scopes = Network.P2P.Payloads.WitnessScope.None;
Assert.ThrowsException<TargetInvocationException>(() => engine.Native.NEO.setRegisterPrice(123));
}
}
}