Skip to content
Merged
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
96 changes: 52 additions & 44 deletions Assets/SequenceSDK/Marketplace/MarketplaceCheckoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -615,66 +615,74 @@ private async Task<CollectibleOrder[]> FetchOffers(string collection, Chain chai
public async Task TestCancelOrder()
{
EndToEndTestHarness testHarness = new EndToEndTestHarness();
Address erc20UniversallyMintable = new Address("0x88e57238a23e2619fd42f479d546560b44c698fe");
Address collection = new Address("0x079294e6ffec16234578c672fa3fbfd4b6c48640");
bool cancelled = false;

testHarness.Login(async wallet =>
WaaSEndToEndTestConfig config = WaaSEndToEndTestConfig.GetConfig();

string email = config.PlayFabEmail;
var request = new LoginWithEmailAddressRequest { Email = email, Password = config.PlayFabPassword };
PlayFabClientAPI.LoginWithEmailAddress(request, result =>
{
await SeedWalletAndCreateListing(wallet, collection, erc20UniversallyMintable);

Order myOrder = null;
int retries = 5;
for (int i = 0; i < retries; i++)
testHarness.LoginWithPlayFab(result, email, async wallet =>
{
CollectibleOrder[] collectibleOrders = await FetchListings(collection, _chain,
new CollectiblesFilter(true, "", null, null, new string[] {wallet.GetWalletAddress()}));
Assert.Greater(collectibleOrders.Length, 0);

myOrder = FindOrderCreatedByWallet(wallet.GetWalletAddress(), collectibleOrders);
if (myOrder != null)
Order myOrder = null;
int retries = 5;
for (int i = 0; i < retries; i++)
{
break;
CollectibleOrder[] collectibleOrders = await FetchListings(collection, _chain,
new CollectiblesFilter(true, "", ordersCreatedBy: new string[] {wallet.GetWalletAddress()}));
Assert.Greater(collectibleOrders.Length, 0);

myOrder = FindOrderCreatedByWallet(wallet.GetWalletAddress(), collectibleOrders);
if (myOrder != null)
{
break;
}
else
{
Debug.Log($"No order created by {wallet.GetWalletAddress()} found. Retrying {i + 1}...");
}
}
else

if (myOrder == null)
{
Debug.Log($"No order created by {wallet.GetWalletAddress()} found. Retrying {i + 1}...");
Assert.Fail($"Failed to find order created by wallet after {retries} retries. Try running {nameof(MarketplaceSeeder.SeedMarketplace_Playfab)} and seeding the marketplace with orders from this wallet first");
}
}

if (myOrder == null)
{
Assert.Fail($"Failed to find order created by wallet after {retries} retries");
}

Checkout checkout = new Checkout(wallet, _chain);
Step[] steps = await checkout.GenerateCancelTransaction(collection, myOrder);
await SubmitStepsAsTransaction(steps, wallet);

for (int i = 0; i < retries; i++)
{
CollectibleOrder[] collectibleOrders = await FetchListings(collection, _chain,
new CollectiblesFilter(true, "", null, null, new string[] {wallet.GetWalletAddress()}));
Assert.Greater(collectibleOrders.Length, 0);
Checkout checkout = new Checkout(wallet, _chain);
Step[] steps = await checkout.GenerateCancelTransaction(collection, myOrder);
await SubmitStepsAsTransaction(steps, wallet);

myOrder = FindOrderCreatedByWallet(wallet.GetWalletAddress(), collectibleOrders);
if (myOrder == null)
for (int i = 0; i < retries; i++)
{
break;
CollectibleOrder[] collectibleOrders = await FetchListings(collection, _chain);
Assert.Greater(collectibleOrders.Length, 0);

myOrder = FindOrderCreatedByWallet(wallet.GetWalletAddress(), collectibleOrders);
if (myOrder == null)
{
break;
}
else
{
Debug.Log($"My order {myOrder.orderId} is still found. Retrying {i + 1}...");
}
}
else

if (myOrder != null)
{
Debug.Log($"My order {myOrder.orderId} is still found. Retrying {i + 1}...");
Assert.Fail(
$"Failed to see that order {myOrder.orderId} was cancelled after {retries} retries");
}
}

if (myOrder != null)
{
Assert.Fail($"Failed to see that order {myOrder.orderId} was cancelled after {retries} retries");
}

cancelled = true;
}, (error, method, email, methods) => { Assert.Fail(error); });
}, error =>
{
Assert.Fail(error.ErrorMessage);
cancelled = true;
}, (error, method, email, methods) => { Assert.Fail(error); });
});

while (!cancelled)
{
Expand All @@ -687,7 +695,7 @@ private Order FindOrderCreatedByWallet(Address walletAddress, CollectibleOrder[]
foreach (var collectibleOrder in collectibleOrders)
{
Order order = collectibleOrder.order;
if (order.createdBy == walletAddress)
if (order != null && order.createdBy.ToLower() == walletAddress.Value.ToLower())
{
return order;
}
Expand Down
194 changes: 133 additions & 61 deletions Assets/SequenceSDK/Marketplace/MarketplaceSeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Numerics;
using System.Threading.Tasks;
using NUnit.Framework;
using PlayFab;
using PlayFab.ClientModels;
using Sequence.Contracts;
using Sequence.EmbeddedWallet;
using Sequence.EmbeddedWallet.Tests;
Expand All @@ -17,91 +19,161 @@ public class MarketplaceSeeder

// [Test]
[Timeout(1800000)]
public async Task SeedMarketplace()
public async Task SeedMarketplace_Playfab()
{
throw new Exception("Please only run this when you need to seed the marketplace for testing as it will create a lot of listings and offers, using a fair amount of gas and credits.");
EndToEndTestHarness testHarness = new EndToEndTestHarness();
bool done = false;
testHarness.Login(async wallet =>
{
Address collection = new Address("0x079294e6ffec16234578c672fa3fbfd4b6c48640");
ERC1155 universallyMintableNft = new ERC1155(collection);

Address erc20UniversallyMintable = new Address("0x88e57238a23e2619fd42f479d546560b44c698fe");
ERC20 universallyMintableToken = new ERC20(erc20UniversallyMintable);

TransactionReturn mintResult = await wallet.SendTransaction(_chain, new Transaction[]
{
new RawTransaction(collection, "0",
universallyMintableNft.MintBatch(wallet.GetWalletAddress(), new BigInteger[] {1, 2, 3, 4, 5}, new BigInteger[] {100000, 100000, 100000, 100000, 100000}).CallData),
new RawTransaction(erc20UniversallyMintable, "0",
universallyMintableToken.Mint(wallet.GetWalletAddress(), 1000000000000).CallData)
});
Assert.IsNotNull(mintResult);
Assert.IsTrue(mintResult is SuccessfulTransactionReturn);

List<Step> finalSteps = new List<Step>();
Address USDC = new Address("0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359");
Address[] possibleCurrencyAddresses = new Address[]
{ USDC };
Checkout checkout = new Checkout(wallet, _chain);
for (int i = 0; i < 10; i++)
WaaSEndToEndTestConfig config = WaaSEndToEndTestConfig.GetConfig();

string email = config.PlayFabEmail;
var request = new LoginWithEmailAddressRequest { Email = email, Password = config.PlayFabPassword };
PlayFabClientAPI.LoginWithEmailAddress(request, result =>
{
testHarness.LoginWithPlayFab(result, email, async wallet =>
{
Step[] steps = await checkout.GenerateListingTransaction(collection, (i % 5 + 1).ToString(), i + 1,
ContractType.ERC1155, possibleCurrencyAddresses.GetRandomObjectFromArray(), 1,
DateTime.Now + TimeSpan.FromDays(365));
if (i % 5 == 3)
try
{
await Task.Delay(1000);
await DoSeedMarketplace(wallet);
}
foreach (var step in steps)
catch (Exception e)
{
finalSteps.Add(step);
Assert.Fail(e.Message);
}
}

for (int i = 0; i < 10; i++)
{
Step[] steps = await checkout.GenerateOfferTransaction(collection, (i % 5 + 1).ToString(), i + 1,
ContractType.ERC1155, possibleCurrencyAddresses.GetRandomObjectFromArray(), 1,
DateTime.Now + TimeSpan.FromDays(365));
if (i % 5 == 3)
finally
{
await Task.Delay(1000);
}
foreach (var step in steps)
{
finalSteps.Add(step);
done = true;
}
}, (error, method, email, methods) =>
{
Assert.Fail(error);
done = true;
});
}, error =>
{
Assert.Fail(error.ErrorMessage);
done = true;
});


while (!done)
{
await Task.Yield();
}
}

// [Test]
[Timeout(1800000)]
public async Task SeedMarketplace_Guest()
{
throw new Exception("Please only run this when you need to seed the marketplace for testing as it will create a lot of listings and offers, using a fair amount of gas and credits.");
EndToEndTestHarness testHarness = new EndToEndTestHarness();
bool done = false;

testHarness.Login(async wallet =>
{
try
{
await DoSeedMarketplace(wallet);
}

Transaction[] transactions = new Transaction[10];
for (int j = 0; j < finalSteps.Count; j+=10)
catch (Exception e)
{
for (int i = 0; i < 10; i++)
{
transactions[i] = new RawTransaction(finalSteps[j+i].to, finalSteps[j+i].value, finalSteps[j+i].data);
}
TransactionReturn result = await wallet.SendTransaction(_chain, transactions);
Assert.IsNotNull(result);
// Assert.IsTrue(result is SuccessfulTransactionReturn);
if (result is SuccessfulTransactionReturn success)
{
Debug.Log(ChainDictionaries.BlockExplorerOf[_chain].AppendTrailingSlashIfNeeded() + "tx/" + success.txHash);
// Application.OpenURL(ChainDictionaries.BlockExplorerOf[_chain].AppendTrailingSlashIfNeeded() + "tx/" + success.txHash);
}
Assert.Fail(e.Message);
}
finally
{
done = true;
}

done = true;
}, (error, method, email, methods) =>
{
Assert.Fail(error);
done = true;
});

while (!done)
{
await Task.Yield();
}
}

private async Task DoSeedMarketplace(IWallet wallet)
{
Address collection = new Address("0x079294e6ffec16234578c672fa3fbfd4b6c48640");
ERC1155 universallyMintableNft = new ERC1155(collection);

Address erc20UniversallyMintable = new Address("0x88e57238a23e2619fd42f479d546560b44c698fe");
ERC20 universallyMintableToken = new ERC20(erc20UniversallyMintable);

TransactionReturn mintResult = await wallet.SendTransaction(_chain, new Transaction[]
{
new RawTransaction(collection, "0",
universallyMintableNft.MintBatch(wallet.GetWalletAddress(),
new BigInteger[] { 1, 2, 3, 4, 5 },
new BigInteger[] { 100000, 100000, 100000, 100000, 100000 }).CallData),
new RawTransaction(erc20UniversallyMintable, "0",
universallyMintableToken.Mint(wallet.GetWalletAddress(), 1000000000000).CallData)
});
Assert.IsNotNull(mintResult);
Assert.IsTrue(mintResult is SuccessfulTransactionReturn);

List<Step> finalSteps = new List<Step>();
Address USDC = new Address("0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359");
Address[] possibleCurrencyAddresses = new Address[] { USDC };
Checkout checkout = new Checkout(wallet, _chain);
for (int i = 0; i < 10; i++)
{
Step[] steps = await checkout.GenerateListingTransaction(collection, (i % 5 + 1).ToString(),
i + 1,
ContractType.ERC1155, possibleCurrencyAddresses.GetRandomObjectFromArray(), 1,
DateTime.Now + TimeSpan.FromDays(365));
if (i % 5 == 3)
{
await Task.Delay(1000);
}

foreach (var step in steps)
{
finalSteps.Add(step);
}
}

for (int i = 0; i < 10; i++)
{
Step[] steps = await checkout.GenerateOfferTransaction(collection, (i % 5 + 1).ToString(),
i + 1,
ContractType.ERC1155, possibleCurrencyAddresses.GetRandomObjectFromArray(), 1,
DateTime.Now + TimeSpan.FromDays(365));
if (i % 5 == 3)
{
await Task.Delay(1000);
}

foreach (var step in steps)
{
finalSteps.Add(step);
}
}

Transaction[] transactions = new Transaction[10];
for (int j = 0; j < finalSteps.Count; j += 10)
{
for (int i = 0; i < 10; i++)
{
transactions[i] = new RawTransaction(finalSteps[j + i].to, finalSteps[j + i].value,
finalSteps[j + i].data);
}

TransactionReturn result = await wallet.SendTransaction(_chain, transactions);
Assert.IsNotNull(result);
// Assert.IsTrue(result is SuccessfulTransactionReturn);
if (result is SuccessfulTransactionReturn success)
{
Debug.Log(ChainDictionaries.BlockExplorerOf[_chain].AppendTrailingSlashIfNeeded() + "tx/" +
success.txHash);
// Application.OpenURL(ChainDictionaries.BlockExplorerOf[_chain].AppendTrailingSlashIfNeeded() + "tx/" + success.txHash);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public enum StepType
createOffer,
signEIP712,
signEIP191,
cancel
}
}
2 changes: 1 addition & 1 deletion Packages/Sequence-Unity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xyz.0xsequence.waas-unity",
"version": "4.0.0",
"version": "4.0.1",
"displayName": "Sequence Embedded Wallet SDK",
"description": "A Unity SDK for Sequence APIs",
"unity": "2021.3",
Expand Down