forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestUtils.cs
57 lines (52 loc) · 2.48 KB
/
TestUtils.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
// Copyright (C) 2015-2024 The Neo Project.
//
// TestUtils.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 Neo.IO;
using Neo.Json;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.Wallets;
using Neo.Wallets.NEP6;
using System;
namespace Neo.Plugins.OracleService.Tests
{
public static class TestUtils
{
public static readonly ProtocolSettings settings = ProtocolSettings.Load("config.json");
public static readonly byte[] ValidatorScript = Contract.CreateSignatureRedeemScript(settings.StandbyCommittee[0]);
public static readonly UInt160 ValidatorScriptHash = ValidatorScript.ToScriptHash();
public static readonly string ValidatorAddress = ValidatorScriptHash.ToAddress(ProtocolSettings.Default.AddressVersion);
public static readonly byte[] MultisigScript = Contract.CreateMultiSigRedeemScript(1, settings.StandbyCommittee);
public static readonly UInt160 MultisigScriptHash = MultisigScript.ToScriptHash();
public static readonly string MultisigAddress = MultisigScriptHash.ToAddress(ProtocolSettings.Default.AddressVersion);
public static StorageKey CreateStorageKey(this NativeContract contract, byte prefix, ISerializable key)
{
var k = new KeyBuilder(contract.Id, prefix);
if (key != null) k = k.Add(key);
return k;
}
public static StorageKey CreateStorageKey(this NativeContract contract, byte prefix, uint value)
{
return new KeyBuilder(contract.Id, prefix).AddBigEndian(value);
}
public static NEP6Wallet GenerateTestWallet(string password)
{
JObject wallet = new JObject();
wallet["name"] = "noname";
wallet["version"] = new Version("1.0").ToString();
wallet["scrypt"] = new ScryptParameters(2, 1, 1).ToJson();
wallet["accounts"] = new JArray();
wallet["extra"] = null;
wallet.ToString().Should().Be("{\"name\":\"noname\",\"version\":\"1.0\",\"scrypt\":{\"n\":2,\"r\":1,\"p\":1},\"accounts\":[],\"extra\":null}");
return new NEP6Wallet(null, password, settings, wallet);
}
}
}