-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from madrazzl3/feature/ticket-contract
[TestNet] Non Fungible Ticket
- Loading branch information
Showing
15 changed files
with
2,379 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,3 +260,4 @@ paket-files/ | |
__pycache__/ | ||
*.pyc | ||
Testnet/AddressMapper/readme.ps1 | ||
.history |
42 changes: 42 additions & 0 deletions
42
Testnet/NonFungibleToken-Ticket/NonFungibleToken.Tests/AddressExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Stratis.SmartContracts; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace NonFungibleTokenContract.Tests | ||
{ | ||
public static class AddressExtensions | ||
{ | ||
private static byte[] HexStringToBytes(string val) | ||
{ | ||
if (val.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) | ||
val = val.Substring(2); | ||
|
||
byte[] ret = new byte[val.Length / 2]; | ||
for (int i = 0; i < val.Length; i = i + 2) | ||
{ | ||
string hexChars = val.Substring(i, 2); | ||
ret[i / 2] = byte.Parse(hexChars, System.Globalization.NumberStyles.HexNumber); | ||
} | ||
return ret; | ||
} | ||
|
||
public static Address HexToAddress(this string hexString) | ||
{ | ||
// uint160 only parses a big-endian hex string | ||
var result = HexStringToBytes(hexString); | ||
return CreateAddress(result); | ||
} | ||
|
||
private static Address CreateAddress(byte[] bytes) | ||
{ | ||
uint pn0 = BitConverter.ToUInt32(bytes, 0); | ||
uint pn1 = BitConverter.ToUInt32(bytes, 4); | ||
uint pn2 = BitConverter.ToUInt32(bytes, 8); | ||
uint pn3 = BitConverter.ToUInt32(bytes, 12); | ||
uint pn4 = BitConverter.ToUInt32(bytes, 16); | ||
|
||
return new Address(pn0, pn1, pn2, pn3, pn4); | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
Testnet/NonFungibleToken-Ticket/NonFungibleToken.Tests/InMemoryState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using Stratis.SmartContracts; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace DividendTokenContract.Tests | ||
{ | ||
public class InMemoryState : IPersistentState | ||
{ | ||
private readonly Dictionary<string, object> storage = new Dictionary<string, object>(); | ||
public bool IsContractResult { get; set; } | ||
public void Clear(string key) => storage.Remove(key); | ||
|
||
public bool ContainsKey(string key) => storage.ContainsKey(key); | ||
|
||
public T GetValue<T>(string key) => (T)storage.GetValueOrDefault(key, default(T)); | ||
|
||
public void AddOrReplace(string key, object value) | ||
{ | ||
if (!storage.TryAdd(key, value)) | ||
storage[key] = value; | ||
} | ||
public Address GetAddress(string key) => GetValue<Address>(key); | ||
|
||
public T[] GetArray<T>(string key) => GetValue<T[]>(key); | ||
|
||
public bool GetBool(string key) => GetValue<bool>(key); | ||
|
||
public byte[] GetBytes(byte[] key) => throw new NotImplementedException(); | ||
|
||
public byte[] GetBytes(string key) => GetValue<byte[]>(key); | ||
|
||
public char GetChar(string key) => GetValue<char>(key); | ||
|
||
public int GetInt32(string key) => GetValue<int>(key); | ||
|
||
public long GetInt64(string key) => GetValue<long>(key); | ||
|
||
public string GetString(string key) => GetValue<string>(key); | ||
|
||
public T GetStruct<T>(string key) | ||
where T : struct => GetValue<T>(key); | ||
|
||
public uint GetUInt32(string key) => GetValue<uint>(key); | ||
|
||
public ulong GetUInt64(string key) => GetValue<ulong>(key); | ||
|
||
public UInt128 GetUInt128(string key) => GetValue<UInt128>(key); | ||
|
||
public UInt256 GetUInt256(string key) => GetValue<UInt256>(key); | ||
|
||
public bool IsContract(Address address) => IsContractResult; | ||
|
||
public void SetAddress(string key, Address value) => AddOrReplace(key, value); | ||
|
||
public void SetArray(string key, Array a) => AddOrReplace(key, a); | ||
|
||
public void SetBool(string key, bool value) => AddOrReplace(key, value); | ||
|
||
public void SetBytes(byte[] key, byte[] value) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void SetBytes(string key, byte[] value) => AddOrReplace(key, value); | ||
|
||
public void SetChar(string key, char value) => AddOrReplace(key, value); | ||
|
||
public void SetInt32(string key, int value) => AddOrReplace(key, value); | ||
|
||
public void SetInt64(string key, long value) => AddOrReplace(key, value); | ||
|
||
public void SetString(string key, string value) => AddOrReplace(key, value); | ||
|
||
public void SetStruct<T>(string key, T value) | ||
where T : struct => AddOrReplace(key, value); | ||
|
||
public void SetUInt32(string key, uint value) => AddOrReplace(key, value); | ||
|
||
public void SetUInt64(string key, ulong value) => AddOrReplace(key, value); | ||
|
||
public void SetUInt128(string key, UInt128 value) => AddOrReplace(key, value); | ||
|
||
public void SetUInt256(string key, UInt256 value) => AddOrReplace(key, value); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Testnet/NonFungibleToken-Ticket/NonFungibleToken.Tests/NonFungibleTokenContract.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | ||
<PackageReference Include="Moq" Version="4.12.0" /> | ||
<PackageReference Include="xunit" Version="2.4.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
<PackageReference Include="FluentAssertions" Version="5.10.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\NonFungibleToken\NonFungibleTokenContract.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.