Skip to content

Commit

Permalink
Initial Check Code in
Browse files Browse the repository at this point in the history
  • Loading branch information
xactant committed Feb 13, 2022
1 parent ba985cc commit e5711ff
Show file tree
Hide file tree
Showing 238 changed files with 25,166 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/

# Visual Studio Code
.vscode

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
msbuild.log
msbuild.err
msbuild.wrn

# test log files
*.testlog
testlog.manifest
Binary file added .vs/MoralisDotNetSdk/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
217 changes: 217 additions & 0 deletions Moralis.Web3Api.Integrated.Tests/AccountTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Moralis.Web3Api.Api;
using Moralis.Web3Api.CloudApi;
using Moralis.Web3Api.Interfaces;
using Moralis.Web3Api.Models;

namespace Moralis.Web3Api.Integrated.Tests
{
class AccountTests : IIntegratedTest
{
private IntegratedTestResult testResults;
public async Task<IntegratedTestResult> RunTests(IWeb3Api web3Api, string address)
{
testResults = new IntegratedTestResult();

Console.WriteLine("Running test GetNativeBalance");
if (await GetNativeBalance (web3Api, address))
{
testResults.PassedTests.Add("GetNativeBalance", "PASSED");
}
else
{
testResults.FailedTests.Add("GetNativeBalance", "FAILED");
}

Console.WriteLine("Running test GetNFTTransfers");
if (await GetNFTTransfers(web3Api, address))
{
testResults.PassedTests.Add("GetNFTTransfers", "PASSED");
}
else
{
testResults.FailedTests.Add("GetNFTTransfers", "FAILED");
}

Console.WriteLine("Running test GetTokenBalances");
if (await GetTokenBalances(web3Api, address))
{
testResults.PassedTests.Add("GetTokenBalances", "PASSED");
}
else
{
testResults.FailedTests.Add("GetTokenBalances", "FAILED");
}

Console.WriteLine("Running test GetTokenTransfers");
if (await GetTokenTransfers(web3Api, address))
{
testResults.PassedTests.Add("GetTokenTransfers", "PASSED");
}
else
{
testResults.FailedTests.Add("GetTokenTransfers", "FAILED");
}

Console.WriteLine("Running test GetTransactions");
if (await GetTransactions(web3Api, address))
{
testResults.PassedTests.Add("GetTransactions", "PASSED");
}
else
{
testResults.FailedTests.Add("GetTransactions", "FAILED");
}

Console.WriteLine("Running test GetNFTs");
if (await GetNFTs(web3Api, address))
{
testResults.PassedTests.Add("GetNFTs", "PASSED");
}
else
{
testResults.FailedTests.Add("GetNFTs", "FAILED");
}

Console.WriteLine("Running test GetNFTsForContract");
if (await GetNFTsForContract(web3Api, address))
{
testResults.PassedTests.Add("GetNFTsForContract", "PASSED");
}
else
{
testResults.FailedTests.Add("GetNFTsForContract", "FAILED");
}
return testResults;
}

private async Task<bool> GetNativeBalance(IWeb3Api web3Api, string address)
{
bool result = true;

try
{
NativeBalance balance = await web3Api.Account.GetNativeBalance(address.ToLower(), ChainList.eth);

result = balance is { };
}
catch (Exception exp)
{
result = false;
}

return result;
}

private async Task<bool> GetNFTTransfers(IWeb3Api web3Api, string address)
{
bool result = true;

try
{
NftTransferCollection balance = await web3Api.Account.GetNFTTransfers(address.ToLower(), ChainList.eth);

result = balance is { } && balance.Result is { };
}
catch (Exception exp)
{
result = false;
}

return result;
}

private async Task<bool> GetTokenBalances(IWeb3Api web3Api, string address)
{
bool result = true;

try
{
List<Erc20TokenBalance> balance = await web3Api.Account.GetTokenBalances(address.ToLower(), ChainList.eth);

result = balance is { };
}
catch (Exception exp)
{
result = false;
}

return result;
}

private async Task<bool> GetTokenTransfers(IWeb3Api web3Api, string address)
{
bool result = true;

try
{
Erc20TransactionCollection balance = await web3Api.Account.GetTokenTransfers(address.ToLower(), ChainList.eth);

result = balance is { };
}
catch (Exception exp)
{
result = false;
}

return result;
}

private async Task<bool> GetTransactions(IWeb3Api web3Api, string address)
{
bool result = true;

try
{
TransactionCollection balance = await web3Api.Account.GetTransactions(address.ToLower(), ChainList.eth);

result = balance is { };
}
catch (Exception exp)
{
result = false;
}

return result;
}

private async Task<bool> GetNFTs(IWeb3Api web3Api, string address)
{
bool result = true;

try
{
NftOwnerCollection resp = await web3Api.Account.GetNFTs(address.ToLower(), ChainList.eth);

result = resp is { };
}
catch (Exception exp)
{
result = false;
}

return result;
}

private async Task<bool> GetNFTsForContract(IWeb3Api web3Api, string address)
{
bool result = true;

try
{
NftOwnerCollection resp = await web3Api.Account.GetNFTsForContract(address.ToLower(), "0x06012c8cf97BEaD5deAe237070F9587f8E7A266d", ChainList.eth);

result = resp is { };
}
catch (Exception exp)
{
result = false;
}

return result;
}
}
}
78 changes: 78 additions & 0 deletions Moralis.Web3Api.Integrated.Tests/DefiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Moralis.Web3Api.Interfaces;
using Moralis.Web3Api.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Moralis.Web3Api.Integrated.Tests
{
class DefiTests : IIntegratedTest
{

private IntegratedTestResult testResults;
public async Task<IntegratedTestResult> RunTests(IWeb3Api web3Api, string address)
{
testResults = new IntegratedTestResult();

Console.WriteLine("Running test GetPairAddress");
if (await GetPairAddress(web3Api))
{
testResults.PassedTests.Add("GetPairAddress", "PASSED");
}
else
{
testResults.FailedTests.Add("GetPairAddress", "FAILED");
}

Console.WriteLine("Running test GetPairReserves");
if (await GetPairReserves(web3Api))
{
testResults.PassedTests.Add("GetPairReserves", "PASSED");
}
else
{
testResults.FailedTests.Add("GetPairReserves", "FAILED");
}

return testResults;
}

private async Task<bool> GetPairAddress(IWeb3Api web3Api)
{
bool result = true;

try
{
ReservesCollection balance = await web3Api.Defi.GetPairAddress("uniswapv2", "0x2b591e99afe9f32eaa6214f7b7629768c40eeb39", "0xdac17f958d2ee523a2206206994597c13d831ec7", ChainList.eth);

result = balance is { };
}
catch (Exception exp)
{
result = false;
}

return result;
}

private async Task<bool> GetPairReserves(IWeb3Api web3Api)
{
bool result = true;

try
{
ReservesCollection balance = await web3Api.Defi.GetPairReserves("0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b974", ChainList.eth);

result = balance is { };
}
catch (Exception exp)
{
result = false;
}

return result;
}

}
}
11 changes: 11 additions & 0 deletions Moralis.Web3Api.Integrated.Tests/IIntegratedTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

using Moralis.Web3Api.Interfaces;
using System.Threading.Tasks;

namespace Moralis.Web3Api.Integrated.Tests
{
interface IIntegratedTest
{
Task<IntegratedTestResult> RunTests(IWeb3Api web3Api, string address);
}
}
23 changes: 23 additions & 0 deletions Moralis.Web3Api.Integrated.Tests/IntegratedTestResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Moralis.Web3Api.Integrated.Tests
{
class IntegratedTestResult
{

public IDictionary<string, string> FailedTests { get; set; }
public IDictionary<string, string> PassedTests { get; set; }

public IntegratedTestResult()
{
FailedTests = new Dictionary<string, string>();
PassedTests = new Dictionary<string, string>();
}

public bool HasFailedTests() => FailedTests.Count > 0;

public int TestCount() => FailedTests.Count + PassedTests.Count;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MoralisDotNet\Moralis.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit e5711ff

Please sign in to comment.