forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUT_NotValidBefore.cs
88 lines (77 loc) · 2.58 KB
/
UT_NotValidBefore.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
// Copyright (C) 2015-2024 The Neo Project.
//
// UT_NotValidBefore.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract.Native;
using System;
namespace Neo.UnitTests.Network.P2P.Payloads
{
[TestClass]
public class UT_NotValidBefore
{
[TestMethod]
public void Size_Get()
{
var test = new NotValidBefore();
test.Size.Should().Be(5);
}
[TestMethod]
public void ToJson()
{
var test = new NotValidBefore
{
Height = 42
};
var json = test.ToJson().ToString();
Assert.AreEqual(@"{""type"":""NotValidBefore"",""height"":42}", json);
}
[TestMethod]
public void DeserializeAndSerialize()
{
var test = new NotValidBefore();
var clone = test.ToArray().AsSerializable<NotValidBefore>();
Assert.AreEqual(clone.Type, test.Type);
// As transactionAttribute
byte[] buffer = test.ToArray();
var reader = new MemoryReader(buffer);
clone = TransactionAttribute.DeserializeFrom(ref reader) as NotValidBefore;
Assert.AreEqual(clone.Type, test.Type);
// Wrong type
buffer[0] = 0xff;
reader = new MemoryReader(buffer);
try
{
TransactionAttribute.DeserializeFrom(ref reader);
Assert.Fail();
}
catch (FormatException) { }
reader = new MemoryReader(buffer);
try
{
new NotValidBefore().Deserialize(ref reader);
Assert.Fail();
}
catch (FormatException) { }
}
[TestMethod]
public void Verify()
{
var test = new NotValidBefore();
var snapshot = TestBlockchain.GetTestSnapshotCache();
test.Height = NativeContract.Ledger.CurrentIndex(snapshot) + 1;
Assert.IsFalse(test.Verify(snapshot, new Transaction()));
test.Height--;
Assert.IsTrue(test.Verify(snapshot, new Transaction()));
}
}
}