Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TestNet] Non Fungible Ticket #92

Merged
merged 7 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,4 @@ paket-files/
__pycache__/
*.pyc
Testnet/AddressMapper/readme.ps1
.history
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);
}
}
}
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);
}
}
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>
Loading