Skip to content

Commit a934750

Browse files
merl111devhawk
andauthored
add static function to create a dummy block for testing (#41)
Co-authored-by: Harry Pierson <[email protected]>
1 parent a23b07b commit a934750

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/bctklib/smart-contract/TestApplicationEngine.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Neo.Network.P2P.Payloads;
99
using Neo.Persistence;
1010
using Neo.SmartContract;
11+
using Neo.SmartContract.Native;
1112

1213
namespace Neo.BlockchainToolkit.SmartContract
1314
{
@@ -36,6 +37,31 @@ static void AddOverload(ImmutableDictionary<uint, InteropDescriptor>.Builder bui
3637
}
3738
}
3839

40+
public static Block CreateDummyBlock(DataCache snapshot, ProtocolSettings settings)
41+
{
42+
var hash = NativeContract.Ledger.CurrentHash(snapshot);
43+
var currentBlock = NativeContract.Ledger.GetBlock(snapshot, hash);
44+
45+
return new Block
46+
{
47+
Header = new Header
48+
{
49+
Version = 0,
50+
PrevHash = hash,
51+
MerkleRoot = new UInt256(),
52+
Timestamp = currentBlock.Timestamp + settings.MillisecondsPerBlock,
53+
Index = currentBlock.Index + 1,
54+
NextConsensus = currentBlock.NextConsensus,
55+
Witness = new Witness
56+
{
57+
InvocationScript = Array.Empty<byte>(),
58+
VerificationScript = Array.Empty<byte>()
59+
},
60+
},
61+
Transactions = Array.Empty<Transaction>()
62+
};
63+
}
64+
3965
private readonly WitnessChecker witnessChecker;
4066

4167
public static Transaction CreateTestTransaction(UInt160 signerAccount, WitnessScope witnessScope = WitnessScope.CalledByEntry)

0 commit comments

Comments
 (0)