Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
55 changes: 55 additions & 0 deletions Assets/SequenceSDK/Ethereum/Tests/ERC1155SaleTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Numerics;
using System.Threading.Tasks;
using NUnit.Framework;
using Sequence;
using Sequence.ABI;
using Sequence.Contracts;
using Sequence.Ethereum.Tests;
using Sequence.Provider;
using Sequence.Wallet;

namespace Sequence.Ethereum
{
public class ERC1155SaleTests
{
private ERC1155Sale _sale = new ERC1155Sale("0xf0056139095224f4eec53c578ab4de1e227b9597");
private IEthClient _client = new SequenceEthClient(Chain.Polygon);

[Test]
public async Task TestGetSaleToken()
{
Address saleCurrency = await _sale.GetPaymentTokenAsync(_client);

Assert.NotNull(saleCurrency);
}

[Test]
public async Task TestMerkleProof()
{
bool valid = await _sale.CheckMerkleProofAsync(_client, new FixedByte(32, ""), new FixedByte[]{}, _sale.Contract.GetAddress(), new FixedByte(32, ""));

Assert.IsFalse(valid);
}

[Test]
public async Task TestGetGlobalSaleDetails()
{
ERC1155Sale.SaleDetails details = await _sale.GetGlobalSaleDetailsAsync(_client);

Assert.NotNull(details);
}

[Test]
public async Task TestGetTokenSaleDetails()
{
ERC1155Sale.SaleDetails details = await _sale.TokenSaleDetailsAsync(_client, 1);

Assert.NotNull(details);
Assert.Greater(details.StartTimeLong, 0);
Assert.Greater(details.EndTimeLong, 0);
Assert.Greater(details.SupplyCap, BigInteger.Zero);
Assert.Greater(details.Cost, BigInteger.Zero);
}
}
}
3 changes: 3 additions & 0 deletions Assets/SequenceSDK/Ethereum/Tests/ERC1155SaleTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private void SetResult(bool success)
_resultText.text = success ? "Success" : "Failed";
}

private string ConvertTime(int timestamp)
private string ConvertTime(long timestamp)
{
var localDateTime = DateTimeOffset.FromUnixTimeSeconds(timestamp).LocalDateTime;
return localDateTime.ToString("dd.MM.yyyy HH:mm:ss");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class PrimarySaleStateERC1155
public BigInteger UserPaymentBalance { get; private set; }
public BigInteger Cost { get; private set; }
public BigInteger SupplyCap { get; private set; }
public int StartTime { get; private set; }
public int EndTime { get; private set; }
public long StartTime { get; private set; }
public long EndTime { get; private set; }
public int TotalMinted { get; private set; }
public Dictionary<BigInteger, TokenSupply> TokenSupplies { get; private set; }

Expand Down Expand Up @@ -81,8 +81,8 @@ private async Task UpdateSaleDetailsAsync()
var globalSaleDetails = await _saleContract.GetGlobalSaleDetailsAsync(_client);
Cost = globalSaleDetails.Cost;
SupplyCap = globalSaleDetails.SupplyCap;
StartTime = globalSaleDetails.StartTime;
EndTime = globalSaleDetails.EndTime;
StartTime = globalSaleDetails.StartTimeLong;
EndTime = globalSaleDetails.EndTimeLong;
}

private async Task UpdatePaymentTokenAsync()
Expand Down Expand Up @@ -127,7 +127,7 @@ private void AddAmountToTokenId(BigInteger tokenId, int amount)
{
TotalMinted += amount;
var curSupplyStr = TokenSupplies[tokenId].supply;
var curSupply = int.TryParse(curSupplyStr, out var value) ? value : 0;
var curSupply = BigInteger.TryParse(curSupplyStr, out var value) ? value : 0;
TokenSupplies[tokenId].supply = (curSupply + amount).ToString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,15 @@ public static FunctionAbi DecodeAbi(string abi)
if (outputsArray != null && outputsArray.Count > 0)
{
string[] outputTypes = ExtractTypes(outputsArray);
returnType = $"({string.Join(", ", outputTypes)})";
if (outputTypes.Length == 1 && outputTypes[0].StartsWith('(') &&
outputTypes[0].EndsWith(')'))
{
returnType = outputTypes[0];
}
else
{
returnType = $"({string.Join(", ", outputTypes)})";
}
}

decodedAbi = AddToDictionary(decodedAbi, functionName, argumentTypes, returnType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

using System;
using Sequence.Utils;
using UnityEngine;

namespace Sequence.ABI
Expand Down Expand Up @@ -91,9 +92,13 @@ public string EncodeToString(object value)
/// <returns>The decoded address string.</returns>
public string DecodeFromString(string encodedString)
{
if (encodedString.IsZeroAddress())
{
return StringExtensions.ZeroAddress;
}

try
{
//cut leading zeros
encodedString = encodedString.Replace("0x", "").TrimStart('0');
return "0x" + encodedString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public string EncodeToString(object value, string[] evmTypes)
throw new ArgumentException($"{nameof(evmTypes)} must not be null");
}

if (value == null)
{
return new string('0', 32);
}

if (value.IsTuple())
{
value = value.ToObjectList();
Expand All @@ -74,7 +79,11 @@ public string EncodeToString(object value, string[] evmTypes)
{
string head_i = "", tail_i = "";
ABIType type = ABI.GetTypeFromEvmName(evmTypes[i]);
ABIType temp = ABI.GetParameterType(valueTuple[i]);
ABIType temp = type;
if (valueTuple[i] != null)
{
temp = ABI.GetParameterType(valueTuple[i]);
}
if (temp != type && type != ABIType.FIXEDARRAY && type != ABIType.DYNAMICARRAY) // If it is a non-array data type, a mismatch will cause encoding issues - with arrays, a mismatch may cause encoding issues but it is difficult to predict
{
throw new ArgumentException($"Argument type is not as expected. Expected: {type} Received: {temp}");
Expand Down Expand Up @@ -116,7 +125,11 @@ public string EncodeToString(object value, string[] evmTypes)
head_i = _numberCoder.EncodeToString((object)(headerTotalByteLength + tailLength));
UnityEngine.Debug.Log("dynamic array head: " + head_i);
//intList.Cast<object>().ToList();
int numberCount = ((IList)valueTuple[i]).Count;
int numberCount = 0;
if (valueTuple[i] != null)
{
numberCount = ((IList)valueTuple[i]).Count;
}
UnityEngine.Debug.Log("number count:" + numberCount);

string numberCountEncoded = _numberCoder.EncodeToString(numberCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public Address GetAddress()
{
return address;
}

public static implicit operator Address(Contract contract)
{
return contract.GetAddress();
}

public async Task<string> Deploy(string bytecode, params object[] constructorArgs)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Sequence.Contracts
{
public abstract class ContractWrapper
{
public Contract Contract { get; private set; }

protected ContractWrapper(Contract contract)
{
this.Contract = contract;
}

protected ContractWrapper(string contractAddress, string abi)
{
this.Contract = new Contract(contractAddress, abi);
}

public static implicit operator Address(ContractWrapper contractWrapper)
{
return contractWrapper.Contract.GetAddress();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading