This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 681
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1519 from oliverw/dev
Dev
- Loading branch information
Showing
51 changed files
with
2,151 additions
and
950 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,3 +204,5 @@ fabric.properties | |
|
||
# End of https://www.toptal.com/developers/gitignore/api/rider | ||
.idea | ||
|
||
.fake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"folders": [ | ||
{ | ||
"path": "." | ||
} | ||
], | ||
"settings": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/Miningcore.Tests/Blockchain/Bitcoin/BitcoinJobTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using Autofac; | ||
using Microsoft.IO; | ||
using Miningcore.Blockchain.Bitcoin; | ||
using Miningcore.Configuration; | ||
using Miningcore.Stratum; | ||
using Miningcore.Tests.Util; | ||
using NBitcoin; | ||
using Newtonsoft.Json; | ||
using NLog; | ||
using Xunit; | ||
#pragma warning disable 8974 | ||
|
||
namespace Miningcore.Tests.Blockchain.Bitcoin; | ||
|
||
public class BitcoinJobTests : TestBase | ||
{ | ||
[Fact] | ||
public void Process_Valid_Block() | ||
{ | ||
var (job, worker) = CreateJob(); | ||
|
||
var submitParams = JsonConvert.DeserializeObject<object[]>("[\"yXHmbak4AdgK5vWamwqFtEijn2NpgLvmi4\",\"00000001\",\"01000000\",\"63445774\",\"51036775\"]", jsonSerializerSettings); | ||
|
||
// extract params | ||
var extraNonce2 = submitParams[2] as string; | ||
var nTime = submitParams[3] as string; | ||
var nonce = submitParams[4] as string; | ||
|
||
// validate & process | ||
var (share, blockHex) = job.ProcessShare(worker, extraNonce2, nTime, nonce); | ||
|
||
Assert.NotNull(share); | ||
Assert.Equal("00000056300e9fd18624edd7eaa8bcd6c8466d7eb8cf91b4e60f9d35fa97f504", share.BlockHash); | ||
Assert.Equal("000000204b0e40a0b523ec3d00fc1a7cee084165a111646b9b35e50936ada1861a0100000362a84c2b4b2e530ec640e2a7f85e05da2c42c8e3645a5bbc2245e74ec1ae967457446371d7011e756703510103000500010000000000000000000000000000000000000000000000000000000000000000ffffffff1d03b66a0c04745744630060000001010000000a4d696e696e67636f7265000000000241016d40000000001976a91464f2b2b84f62d68a2cd7f7f5fb2b5aa75ef716d788ac2c56f32a000000001976a9141a9cab092e161f3822af4b27f4f33051dbb7d32088ac00000000460200b66a0c00fbab6816312c05803d026cce30fec0332c059f66e421ab0bf65b96ea9efb8a22e12cfc31666208b47a006e5b74f95a4c0797b6bc620ea1cc07cb53616e547302", blockHex); | ||
Assert.Equal(813750, share.BlockHeight); | ||
Assert.True(share.IsBlockCandidate); | ||
} | ||
|
||
[Fact] | ||
public void Process_Duplicate_Submission() | ||
{ | ||
var (job, worker) = CreateJob(); | ||
|
||
var submitParams = JsonConvert.DeserializeObject<object[]>("[\"yXHmbak4AdgK5vWamwqFtEijn2NpgLvmi4\",\"00000001\",\"01000000\",\"63445774\",\"51036775\"]", jsonSerializerSettings); | ||
|
||
// extract params | ||
var extraNonce2 = submitParams[2] as string; | ||
var nTime = submitParams[3] as string; | ||
var nonce = submitParams[4] as string; | ||
|
||
// validate & process | ||
var (share, _) = job.ProcessShare(worker, extraNonce2, nTime, nonce); | ||
|
||
Assert.NotNull(share); | ||
Assert.True(share.IsBlockCandidate); | ||
|
||
Assert.ThrowsAny<StratumException>(()=> job.ProcessShare(worker, extraNonce2, nTime, nonce)); | ||
} | ||
|
||
[Fact] | ||
public void Process_Invalid_Nonce() | ||
{ | ||
var (job, worker) = CreateJob(); | ||
|
||
var submitParams = JsonConvert.DeserializeObject<object[]>("[\"yXHmbak4AdgK5vWamwqFtEijn2NpgLvmi4\",\"00000001\",\"01000000\",\"63445774\",\"61036775\"]", jsonSerializerSettings); | ||
|
||
// extract params | ||
var extraNonce2 = submitParams[2] as string; | ||
var nTime = submitParams[3] as string; | ||
var nonce = submitParams[4] as string; | ||
|
||
// validate & process | ||
Assert.ThrowsAny<StratumException>(()=> job.ProcessShare(worker, extraNonce2, nTime, nonce)); | ||
} | ||
|
||
[Fact] | ||
public void Process_Invalid_Time() | ||
{ | ||
var (job, worker) = CreateJob(); | ||
|
||
var submitParams = JsonConvert.DeserializeObject<object[]>("[\"yXHmbak4AdgK5vWamwqFtEijn2NpgLvmi4\",\"00000001\",\"01000000\",\"13445774\",\"51036775\"]", jsonSerializerSettings); | ||
|
||
// extract params | ||
var extraNonce2 = submitParams[2] as string; | ||
var nTime = submitParams[3] as string; | ||
var nonce = submitParams[4] as string; | ||
|
||
// validate & process | ||
Assert.ThrowsAny<StratumException>(()=> job.ProcessShare(worker, extraNonce2, nTime, nonce)); | ||
} | ||
|
||
private (BitcoinJob, StratumConnection) CreateJob() | ||
{ | ||
var job = new BitcoinJob(); | ||
var coin = (BitcoinTemplate) ModuleInitializer.CoinTemplates["dash"]; | ||
var pc = new PoolConfig { Template = coin }; | ||
|
||
var blockTemplate = JsonConvert.DeserializeObject<Miningcore.Blockchain.Bitcoin.DaemonResponses.BlockTemplate>("{\"version\":536870912,\"previousBlockhash\":\"0000011a86a1ad3609e5359b6b6411a1654108ee7c1afc003dec23b5a0400e4b\",\"coinbaseValue\":1801475949,\"target\":\"000001d771000000000000000000000000000000000000000000000000000000\",\"nonceRange\":\"00000000ffffffff\",\"curTime\":1665423220,\"bits\":\"1e01d771\",\"height\":813750,\"transactions\":[],\"coinbaseAux\":{\"flags\":null},\"default_witness_commitment\":null,\"capabilities\":[\"proposal\"],\"rules\":[\"csv\",\"dip0001\",\"bip147\",\"dip0003\",\"dip0008\",\"realloc\",\"dip0020\",\"dip0024\"],\"vbavailable\":{},\"vbrequired\":0,\"longpollid\":\"0000011a86a1ad3609e5359b6b6411a1654108ee7c1afc003dec23b5a0400e4b814670\",\"mintime\":1665422408,\"mutable\":[\"time\",\"transactions\",\"prevblock\"],\"sigoplimit\":40000,\"sizelimit\":2000000,\"previousbits\":\"1e01bee4\",\"masternode\":[{\"payee\":\"yVXDAM73Tg6A44Bm3qduXsMCYxzuqBCT48\",\"script\":\"76a91464f2b2b84f62d68a2cd7f7f5fb2b5aa75ef716d788ac\",\"amount\":1080885569}],\"masternode_payments_started\":true,\"masternode_payments_enforced\":true,\"superblock\":[],\"superblocks_started\":true,\"superblocks_enabled\":true,\"coinbase_payload\":\"0200b66a0c00fbab6816312c05803d026cce30fec0332c059f66e421ab0bf65b96ea9efb8a22e12cfc31666208b47a006e5b74f95a4c0797b6bc620ea1cc07cb53616e547302\"}", jsonSerializerSettings); | ||
var clock = MockMasterClock.FromTicks(638010200200475015); | ||
var poolAddressDestination = BitcoinUtils.AddressToDestination("yNkA6gVSPqKzW6WmJtTazRLKbSkQA5ND2h", Network.TestNet); | ||
var network = Network.GetNetwork("testnet"); | ||
|
||
var context = new BitcoinWorkerContext | ||
{ | ||
Miner = "yXHmbak4AdgK5vWamwqFtEijn2NpgLvmi4", | ||
ExtraNonce1 = "60000001", | ||
Difficulty = 0.01, | ||
UserAgent = "cpuminer-multi/1.3.1" | ||
}; | ||
|
||
var worker = new StratumConnection(new NullLogger(LogManager.LogFactory), container.Resolve<RecyclableMemoryStreamManager>(), clock, "1", false); | ||
worker.SetContext(context); | ||
|
||
job.Init(blockTemplate, "1", pc, null, new ClusterConfig(), clock, poolAddressDestination, network, false, | ||
coin.ShareMultiplier, coin.CoinbaseHasherValue, coin.HeaderHasherValue, coin.BlockHasherValue); | ||
|
||
return (job, worker); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.Serialization; | ||
using Miningcore.Configuration; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
#pragma warning disable 8974 | ||
|
||
namespace Miningcore.Tests.Coins; | ||
|
||
public class CoinTemplateValidationTest : TestBase | ||
{ | ||
private readonly ITestOutputHelper output; | ||
|
||
public CoinTemplateValidationTest(ITestOutputHelper output) | ||
{ | ||
this.output = output; | ||
} | ||
|
||
[Fact] | ||
public void Validate_Coin_Templates() | ||
{ | ||
var cft = typeof(CoinFamily).GetTypeInfo(); | ||
var cryptonightHashType = typeof(CryptonightHashType).GetTypeInfo(); | ||
|
||
foreach(var template in ModuleInitializer.CoinTemplates) | ||
{ | ||
var t = template.Value; | ||
|
||
output.WriteLine($"* {t.Name ?? t.Symbol ?? t.CanonicalName}"); | ||
|
||
Assert.NotEmpty(t.Name); | ||
Assert.NotEmpty(t.Symbol); | ||
Assert.True(CoinTemplate.Families.ContainsKey(t.Family)); | ||
Assert.NotNull(cft.DeclaredMembers.SingleOrDefault(x => x.Name == t.Family.ToString())?.GetCustomAttribute<EnumMemberAttribute>(false)); | ||
|
||
switch(t) | ||
{ | ||
case BitcoinTemplate bt when t is BitcoinTemplate: | ||
{ | ||
if(bt.CoinbaseHasher != null) | ||
Assert.Null(Record.Exception(() => bt.CoinbaseHasherValue)); | ||
|
||
if(bt.HeaderHasher != null) | ||
Assert.Null(Record.Exception(() => bt.HeaderHasherValue)); | ||
|
||
if(bt.BlockHasher != null) | ||
Assert.Null(Record.Exception(() => bt.BlockHasherValue)); | ||
|
||
if(bt.PoSBlockHasher != null) | ||
Assert.Null(Record.Exception(() => bt.PoSBlockHasherValue)); | ||
break; | ||
} | ||
|
||
case CryptonoteCoinTemplate cnt when t is CryptonoteCoinTemplate: | ||
{ | ||
Assert.NotNull(cryptonightHashType.DeclaredMembers.SingleOrDefault(x => x.Name == cnt.Hash.ToString())?.GetCustomAttribute<EnumMemberAttribute>(false)); | ||
|
||
break; | ||
} | ||
} | ||
|
||
Assert.NotEmpty(t.GetAlgorithmName()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
using Autofac; | ||
using Newtonsoft.Json; | ||
|
||
namespace Miningcore.Tests; | ||
|
||
public abstract class TestBase | ||
{ | ||
protected TestBase() | ||
{ | ||
ModuleInitializer.Initialize(); | ||
|
||
container = ModuleInitializer.Container; | ||
jsonSerializerSettings = container.Resolve<JsonSerializerSettings>(); | ||
} | ||
|
||
protected readonly IContainer container; | ||
protected readonly JsonSerializerSettings jsonSerializerSettings; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.