Skip to content

Commit

Permalink
Full 1.3 support (#42)
Browse files Browse the repository at this point in the history
* ValidateKeyringPassphrase

* UnlockKeyring

* MigrateKeyring

* IsKeyringLocked

* SetKeyringPassphrase

* RemoveKeyringPassphrase

* GetKeyForFingerprint

* CheckKeys

* GetFirstPrivateKey

* GetAllPrivateKeys

* sspelling

* DeleteKeyByFingerprint

* DeleteAllKeys

* AddPrivateKey

* closes #34

* GetLoggedInFingerprint
#34

* refine test

* PrivateKeyDetails

* remove AddKeyAndRestoreBackup

* #35
removed skipImport

* #35 remove CreateBackup

* #35 add fingerprint to return

* #35 replicate push_tx on wallet interface

* #35 remove default backup host stuff

* #35 replace references to colour with CAT

* #35 replace byte type with WalletType

* #35 GetAssetId

* #35 AssetIdToName

* #35 add memos to cat_spend

* #36 update CreateOfferForIds

* #36

* #36 Add TradeManager

* #36 add CatInfo

* #36 remove GetDiscrepenciesForOffer

* #36 CheckOfferValidity

* #36 GetOffer

* #36 GetOfferSummary

* #36 CancelOffer

* #36 TakeOffer

* #36 update TradeRecord

* #36 GetOffersCount

* #36 GetAllOffers

* #35 add search options to GetTransactions

* #35 add announcements to createSignedTx

* #35 add memos to SendTransaction

* versioning

* add overload for creating cat wallet with defualt name

* wallet id on AssetIdToName is nullable

* catch init erros

* update deps

* dont require cat name on wallet creation

* make fee ulong

* add OfferSummary type

* comments

* #38

* closes #38

* correct serialziation names for peercounts

* closes #39

* some comments

* create cat wallet test

* setname tests

* get asset id test

* AssetIdToName test

* Add TradeManager tests and fix a couple things

* spelling

* missing default fee = 0

* change Factory name to be more expliciti

* remove unneed success check

* remove temp object in GetOffers

* use named params to avoid mixups

* Update README.md

* align tests to test server

Co-authored-by: andyraddatz <[email protected]>
  • Loading branch information
dkackman and andyraddatz authored Mar 25, 2022
1 parent 79d4e47 commit 46d9a8e
Show file tree
Hide file tree
Showing 43 changed files with 1,456 additions and 487 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ https://dkackman.github.io/chia-dotnet/
- Coverage of all of chia's rpc endpoints
- Daemon, Full Node, Farmer, Harvester Wallet, Plotter
- Coverage of all of the methods at each endpoint
- as of 1.2.11 (if you find something missing please create an issue)
- as of 1.3.1 (if you find something missing please create an issue)
- Static types for chia input and outputs
- Supports connecting via the `daemon` on `wss` or directly to each service with `https`
- both `https` and `wss` use tha same interfaces so switching is seemless
Expand Down
78 changes: 78 additions & 0 deletions src/chia-dotnet.tests/CATWalletTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Threading;
using System.Threading.Tasks;
using System;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace chia.dotnet.tests
{
[TestClass]
[TestCategory("Integration")]
//[Ignore("Needs a CAT wallet")]
public class CATWalletTests
{
private static CATWallet _theWallet;

[ClassInitialize]
public static async Task Initialize(TestContext context)
{
using var cts = new CancellationTokenSource(30000);
var rpcClient = Factory.CreateWebsocketClient();
await rpcClient.Connect(cts.Token);

var daemon = new DaemonProxy(rpcClient, "unit_tests");
await daemon.RegisterService();

var walletProxy = new WalletProxy(rpcClient, "unit_tests");

_ = await walletProxy.LogIn(cts.Token);

// IMPORTANT
// SET this wallet ID to a coloroured coin wallet
_theWallet = new CATWallet(2, walletProxy);
}

[ClassCleanup()]
public static void ClassCleanup()
{
_theWallet.WalletProxy.RpcClient?.Dispose();
}

[TestMethod()]
public async Task GetName()
{
using var cts = new CancellationTokenSource(20000);

var name = await _theWallet.GetName(cts.Token);

Assert.IsNotNull(name);
}

[TestMethod()]
public async Task SetName()
{
using var cts = new CancellationTokenSource(20000);

var originalName = await _theWallet.GetName(cts.Token);

var newName = Guid.NewGuid().ToString();
await _theWallet.SetName(newName, cts.Token);

var name = await _theWallet.GetName(cts.Token);

Assert.AreEqual(newName, name);
await _theWallet.SetName(originalName, cts.Token);
}


[TestMethod()]
public async Task GetAssetId()
{
using var cts = new CancellationTokenSource(20000);

var id = await _theWallet.GetAssetId(cts.Token);

Assert.IsNotNull(id);
}
}
}
54 changes: 0 additions & 54 deletions src/chia-dotnet.tests/ColouredCoinWalletTests.cs

This file was deleted.

57 changes: 57 additions & 0 deletions src/chia-dotnet.tests/CrawlerProxyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace chia.dotnet.tests
{
[TestClass]
[TestCategory("Integration")]
public class CrawlerProxyTests
{
private static CrawlerProxy _theCrawler;

[ClassInitialize]
public static async Task Initialize(TestContext context)
{
try
{
var rpcClient = Factory.CreateDirectRpcClientFromHardcodedLocation(8561, "crawler");

await Task.CompletedTask;
_theCrawler = new CrawlerProxy(rpcClient, "unit_tests");
}
catch (Exception e)
{
Assert.Fail(e.Message);
}
}

[ClassCleanup()]
public static void ClassCleanup()
{
_theCrawler.RpcClient?.Dispose();
}

[TestMethod()]
public async Task GetPeerCounts()
{
using var cts = new CancellationTokenSource(20000);

var counts = await _theCrawler.GetPeerCounts(cts.Token);

Assert.IsNotNull(counts);
}

[TestMethod()]
public async Task GetIPs()
{
using var cts = new CancellationTokenSource(20000);

var ips = await _theCrawler.GetIPs(DateTime.Now - TimeSpan.FromDays(2), cancellationToken: cts.Token);

Assert.IsNotNull(ips);
}
}
}
4 changes: 2 additions & 2 deletions src/chia-dotnet.tests/DIDWalletTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public class DIDWalletTests
public static async Task Initialize(TestContext context)
{
using var cts = new CancellationTokenSource(30000);
var rpcClient = Factory.CreateRpcClientFromHardcodedLocation();
var rpcClient = Factory.CreateWebsocketClient();
await rpcClient.Connect(cts.Token);

var daemon = new DaemonProxy(rpcClient, "unit_tests");
await daemon.RegisterService(cts.Token);

var walletProxy = new WalletProxy(rpcClient, "unit_tests");
_ = await walletProxy.LogIn(false, cts.Token);
_ = await walletProxy.LogIn(cts.Token);
// SET this wallet ID to a coloroured coin wallet
_theWallet = new DIDWallet(2, walletProxy);
}
Expand Down
139 changes: 135 additions & 4 deletions src/chia-dotnet.tests/DaemonTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

using System.Threading;
using System.Threading.Tasks;
using System.Linq;

using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand All @@ -18,11 +19,19 @@ public class DaemonTests
[ClassInitialize]
public static async Task Initialize(TestContext context)
{
using var cts = new CancellationTokenSource(2000);
var rpcClient = Factory.CreateRpcClientFromHardcodedLocation();
await rpcClient.Connect(cts.Token);
try
{
using var cts = new CancellationTokenSource(20000);
var rpcClient = Factory.CreateWebsocketClient();
await rpcClient.Connect(cts.Token);

_theDaemon = new DaemonProxy(rpcClient, "unit_tests");
_theDaemon = new DaemonProxy(rpcClient, "unit_tests");
}
catch (System.Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
throw;
}
}

[ClassCleanup()]
Expand Down Expand Up @@ -58,6 +67,128 @@ public async Task GetFarmerIsRunning()
Assert.IsTrue(running);
}

[TestMethod]
[ExpectedException(typeof(ResponseException))]
public async Task ValidateInvalidKeyringPassphrase()
{
using var cts = new CancellationTokenSource(15000);

await _theDaemon.ValidateKeyringPassphrase("spoon", cts.Token);
}

[TestMethod]
[ExpectedException(typeof(ResponseException))]
public async Task UnlockKeyringInvalid()
{
using var cts = new CancellationTokenSource(15000);

await _theDaemon.UnlockKeyring("spoon", cts.Token);
}

[TestMethod]
public async Task UnlockKeyringValid()
{
using var cts = new CancellationTokenSource(15000);
var status = await _theDaemon.GetKeyringStatus(cts.Token);
if (status.UserPassphraseIsSet)
{
await _theDaemon.UnlockKeyring("sp00n3!!", cts.Token);

var locked = await _theDaemon.IsKeyringLocked(cts.Token);

Assert.IsFalse(locked);
}
}

[TestMethod]
[Ignore("CAUTION")]
public async Task MigrateKeyring()
{
using var cts = new CancellationTokenSource(15000);
var status = await _theDaemon.GetKeyringStatus(cts.Token);
if (!status.UserPassphraseIsSet)
{
await _theDaemon.MigrateKeyring("sp00n3!!", "super secure utensil", true, false, cts.Token);
}
}

[TestMethod]
public async Task SetKeyringPassphrase()
{
using var cts = new CancellationTokenSource(15000);
var status = await _theDaemon.GetKeyringStatus(cts.Token);
if (status.UserPassphraseIsSet)
{
await _theDaemon.SetKeyringPassphrase("sp00n3!!", "sp00n3!!!", "super duper secure utensil", true, cts.Token);
}
}

[TestMethod]
public async Task RemoveKeyringPassphrase()
{
using var cts = new CancellationTokenSource(15000);

var status = await _theDaemon.GetKeyringStatus(cts.Token);
if (status.UserPassphraseIsSet)
{
await _theDaemon.RemoveKeyringPassphrase("sp00n3!!!", cts.Token);
}
}

[TestMethod]
public async Task IsKeyringLocked()
{
using var cts = new CancellationTokenSource(15000);

var locked = await _theDaemon.IsKeyringLocked(cts.Token);

Assert.IsTrue(locked);
}

[TestMethod]
public async Task GetKeyForFingerprint()
{
using var cts = new CancellationTokenSource(15000);

var proxy = _theDaemon.CreateProxyFrom<WalletProxy>();
var prints = await proxy.GetPublicKeys(cts.Token);
Assert.IsTrue(prints.Any());

var key = await _theDaemon.GetKeyForFingerprint(prints.First(), cts.Token);

Assert.IsNotNull(key);
}

[TestMethod]
public async Task GetAllPrivateKeys()
{
using var cts = new CancellationTokenSource(15000);

var keys = await _theDaemon.GetAllPrivateKeys(cts.Token);

Assert.IsNotNull(keys);
Assert.IsTrue(keys.Any());
}

[TestMethod]
[Ignore("This seems to put the daemon out to lunch")]
public async Task CheckKeys()
{
using var cts = new CancellationTokenSource(30000);

await _theDaemon.CheckKeys("~/.chia/mainnet/config", cts.Token);
}

[TestMethod]
public async Task GetFirstPrivateKey()
{
using var cts = new CancellationTokenSource(30000);

var key = await _theDaemon.GetFirstPrivateKey(cts.Token);

Assert.IsNotNull(key);
}

[TestMethod]
public async Task CreateFullNodeFrom()
{
Expand Down
Loading

0 comments on commit 46d9a8e

Please sign in to comment.