Skip to content

Commit

Permalink
Block hashes on input
Browse files Browse the repository at this point in the history
  • Loading branch information
meevee98 committed Sep 30, 2022
1 parent cd39ea9 commit 92b9e1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/Neo.TestEngine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,24 @@ private static ContractParameter[] GetStackItemParameters(JArray parameters)

private static TestBlock BlockFromJson(JToken blockJson)
{
var transactions = blockJson["transactions"] as JArray;
JObject blockJsonObject = (JObject)blockJson;
var transactions = blockJsonObject["transactions"] as JArray;

if (!uint.TryParse(blockJson["index"].AsString(), out var blockIndex))
if (!uint.TryParse(blockJsonObject["index"].AsString(), out var blockIndex))
{
throw new FormatException(GetInvalidTypeMessage("uint", "blockIndex"));
}
if (!ulong.TryParse(blockJson["timestamp"].AsString(), out var blockTimestamp))
if (!ulong.TryParse(blockJsonObject["timestamp"].AsString(), out var blockTimestamp))
{
throw new FormatException(GetInvalidTypeMessage("ulong", "blockTimestamp"));
}

UInt256? blockHash;
if (!blockJsonObject.ContainsProperty("hash") || !UInt256.TryParse(blockJsonObject["hash"].AsString(), out blockHash))
{
blockHash = null;
}

var txStates = transactions.Select(tx => TxStateFromJson(tx)).ToArray();
var block = new Block()
{
Expand All @@ -471,7 +478,7 @@ private static TestBlock BlockFromJson(JToken blockJson)
Transactions = txStates.Select(tx => tx.Transaction).ToArray()
};

return new TestBlock(block, txStates);
return new TestBlock(block, txStates, blockHash);
}

private static Transaction TxFromJson(JToken txJson)
Expand Down
4 changes: 3 additions & 1 deletion src/Neo.TestEngine/TestBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ namespace Neo.TestingEngine
public class TestBlock
{
internal Block Block { get; }
internal UInt256? Hash { get; }
internal TransactionState[] Transactions { get; }

public TestBlock(Block block, TransactionState[] txs)
public TestBlock(Block block, TransactionState[] txs, UInt256? blockHash = null)
{
Block = block;
Hash = blockHash;
Transactions = txs;
}
}
Expand Down

0 comments on commit 92b9e1d

Please sign in to comment.