Skip to content

Commit

Permalink
Merge pull request #32 from make-software/casper-net-sdk-v2
Browse files Browse the repository at this point in the history
Prepare release casper-net-sdk v2.0.0
  • Loading branch information
mrkara authored Jul 18, 2023
2 parents 258350a + 54d1a6b commit 3754779
Show file tree
Hide file tree
Showing 32 changed files with 1,182 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/integration-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ jobs:
- 11101:11101
- 14101:14101
- 18101:18101
- 25101:25101
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 7.0.x
- name: Obtain faucet secret key from container
run: docker exec -t casper-nctl cat /home/casper/casper-node/utils/nctl/assets/net-1/faucet/secret_key.pem > Casper.Network.SDK.Test/TestData/faucetact.pem
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal --settings Casper.Network.SDK.Test/test.runsettings --filter="TestCategory=NCTL"
run: dotnet test --no-build --verbosity normal --settings Casper.Network.SDK.Test/test.runsettings --filter="TestCategory=NCTL"
2 changes: 1 addition & 1 deletion .github/workflows/nuget-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 7.0.x

- name: publish on version change
id: publish_nuget
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push-to-github-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 7.0.x
- name: Create nuget package
run: dotnet pack --configuration Release -o out
- name: Publish Nuget to GitHub registry
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ All notable changes to this project will be documented in this file. The format
[comment]: <> (Fixed: any bug fixes)
[comment]: <> (Security: in case of vulnerabilities)

## [2.0.0]

### Added
* Added client method for new `query_balance` RPC endpoint.
* Added client method for new `speculative_exec` feature in casper node v1.5.0.
* Added client method for new `info_get_chainspec` RPC endpoint.
* Added client method for new `chain_get_era_summary` RPC endpoint.
* Added support for `block_height` parameter in `query_global_state` RPC endpoint.
* Added new key types: `chainspec-registry-`, `system-contract-registry-`, `checksum-registry-`, `era-summary`, `unbond-`.
* Added support for new key prefix 'contract-package-'.
* Added new fields related to node sync in `info_get_status` RPC response.
* Added support optional fields in `info_get_deploy` RPC response.
* Added `lock_status` field to `ContractPackageStatus`.

### Changed
* The SDK now builds with .NET 7 Framework.
*
## [1.1.2]

### Added
Expand Down Expand Up @@ -39,6 +56,7 @@ All notable changes to this project will be documented in this file. The format
### Added
* Initial release of Casper .NET SDK.

[2.0.0]: https://github.com/make-software/casper-net-sdk/releases/tag/v2.0.0
[1.1.2]: https://github.com/make-software/casper-net-sdk/releases/tag/v1.1.2
[1.1.1]: https://github.com/make-software/casper-net-sdk/releases/tag/v1.1.1
[1.1.0]: https://github.com/make-software/casper-net-sdk/releases/tag/v1.1.0
Expand Down
10 changes: 5 additions & 5 deletions Casper.Network.SDK.Test/Casper.Network.SDK.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>

<IsPackable>false</IsPackable>

<RootNamespace>NetCasperTest</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Include="coverlet.collector" Version="3.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
132 changes: 129 additions & 3 deletions Casper.Network.SDK.Test/GlobalStateKeyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class GlobalStateKeyTest
public void AccountHashTest()
{
const string accountHash = "account-hash-0101010101010101010101010101010101010101010101010101010101010101";
Assert.IsTrue(accountHash.StartsWith(AccountHashKey.KEYPREFIX));

var key = GlobalStateKey.FromString(accountHash);
Assert.IsNotNull(key);
Assert.IsTrue(key is AccountHashKey);
Expand All @@ -34,13 +36,15 @@ public void AccountHashFromPublicKeyTest()

var key2 = new AccountHashKey(publicKey);
Assert.IsNotNull(key2);
Assert.IsTrue(key2.ToString().StartsWith("account-hash-"));
Assert.IsTrue(key2.ToString().StartsWith(AccountHashKey.KEYPREFIX));
}

[Test]
public void HashKeyTest()
{
const string hashKey = "hash-0202020202020202020202020202020202020202020202020202020202020202";
Assert.IsTrue(hashKey.StartsWith(HashKey.KEYPREFIX));

var key = GlobalStateKey.FromString(hashKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is HashKey);
Expand All @@ -58,6 +62,8 @@ public void HashKeyTest()
public void URefTest()
{
const string urefKey = "uref-0303030303030303030303030303030303030303030303030303030303030303-001";
Assert.IsTrue(urefKey.StartsWith(URef.KEYPREFIX));

var key = GlobalStateKey.FromString(urefKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is URef);
Expand All @@ -77,6 +83,8 @@ public void URefTest()
public void TransferKeyTest()
{
const string transferKey = "transfer-0404040404040404040404040404040404040404040404040404040404040404";
Assert.IsTrue(transferKey.StartsWith(TransferKey.KEYPREFIX));

var key = GlobalStateKey.FromString(transferKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is TransferKey);
Expand All @@ -94,6 +102,8 @@ public void TransferKeyTest()
public void DeployInfoKeyTest()
{
const string deployKey = "deploy-0505050505050505050505050505050505050505050505050505050505050505";
Assert.IsTrue(deployKey.StartsWith(DeployInfoKey.KEYPREFIX));

var key = GlobalStateKey.FromString(deployKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is DeployInfoKey);
Expand All @@ -111,6 +121,8 @@ public void DeployInfoKeyTest()
public void EraInfoKeyTest()
{
const string eraInfoKey = "era-12345";
Assert.IsTrue(eraInfoKey.StartsWith(EraInfoKey.KEYPREFIX));

var key = GlobalStateKey.FromString(eraInfoKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is EraInfoKey);
Expand All @@ -131,6 +143,8 @@ public void EraInfoKeyTest()
public void BalanceKeyTest()
{
const string balanceKey = "balance-0707070707070707070707070707070707070707070707070707070707070707";
Assert.IsTrue(balanceKey.StartsWith(BalanceKey.KEYPREFIX));

var key = GlobalStateKey.FromString(balanceKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is BalanceKey);
Expand All @@ -148,6 +162,8 @@ public void BalanceKeyTest()
public void BidKeyTest()
{
const string bidKey = "bid-0808080808080808080808080808080808080808080808080808080808080808";
Assert.IsTrue(bidKey.StartsWith(BidKey.KEYPREFIX));

var key = GlobalStateKey.FromString(bidKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is BidKey);
Expand All @@ -165,6 +181,8 @@ public void BidKeyTest()
public void WithdrawKeyTest()
{
const string withdrawKey = "withdraw-0909090909090909090909090909090909090909090909090909090909090909";
Assert.IsTrue(withdrawKey.StartsWith(WithdrawKey.KEYPREFIX));

var key = GlobalStateKey.FromString(withdrawKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is WithdrawKey);
Expand All @@ -182,6 +200,8 @@ public void WithdrawKeyTest()
public void DictionaryKeyTest()
{
const string dictionaryKey = "dictionary-1010101010101010101010101010101010101010101010101010101010101010";
Assert.IsTrue(dictionaryKey.StartsWith(DictionaryKey.KEYPREFIX));

var key = GlobalStateKey.FromString(dictionaryKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is DictionaryKey);
Expand All @@ -195,6 +215,112 @@ public void DictionaryKeyTest()
Assert.IsTrue(key.GetBytes().SequenceEqual(bytes));
}

[Test]
public void SystemContractRegistryKeyTest()
{
const string systemContractKey = "system-contract-registry-0909090909090909090909090909090909090909090909090909090909090909";
Assert.IsTrue(systemContractKey.StartsWith(SystemContractRegistryKey.KEYPREFIX));

var key = GlobalStateKey.FromString(systemContractKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is SystemContractRegistryKey);
Assert.AreEqual(systemContractKey, key.ToString());

var bytes = Hex.Decode("0a0909090909090909090909090909090909090909090909090909090909090909");
key = GlobalStateKey.FromBytes(bytes);
Assert.IsNotNull(key);
Assert.IsTrue(key is SystemContractRegistryKey);
Assert.AreEqual(systemContractKey, key.ToString());
Assert.IsTrue(key.GetBytes().SequenceEqual(bytes));
}

[Test]
public void ErasummaryKeyTest()
{
const string eraSummaryKey = "era-summary-0909090909090909090909090909090909090909090909090909090909090909";
Assert.IsTrue(eraSummaryKey.StartsWith(EraSummaryKey.KEYPREFIX));

var key = GlobalStateKey.FromString(eraSummaryKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is EraSummaryKey);
Assert.AreEqual(eraSummaryKey, key.ToString());

var bytes = Hex.Decode("0b0909090909090909090909090909090909090909090909090909090909090909");
key = GlobalStateKey.FromBytes(bytes);
Assert.IsNotNull(key);
Assert.IsTrue(key is EraSummaryKey);
Assert.AreEqual(eraSummaryKey, key.ToString());
Assert.IsTrue(key.GetBytes().SequenceEqual(bytes));
}

[Test]
public void UnbondKeyTest()
{
const string unbondKey = "unbond-0909090909090909090909090909090909090909090909090909090909090909";
Assert.IsTrue(unbondKey.StartsWith(UnbondKey.KEYPREFIX));

var key = GlobalStateKey.FromString(unbondKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is UnbondKey);
Assert.AreEqual(unbondKey, key.ToString());

var bytes = Hex.Decode("0c0909090909090909090909090909090909090909090909090909090909090909");
key = GlobalStateKey.FromBytes(bytes);
Assert.IsNotNull(key);
Assert.IsTrue(key is UnbondKey);
Assert.AreEqual(unbondKey, key.ToString());
Assert.IsTrue(key.GetBytes().SequenceEqual(bytes));
}

[Test]
public void ChainspecRegistryKeyTest()
{
const string chainspecRegistryKey = "chainspec-registry-0909090909090909090909090909090909090909090909090909090909090909";
Assert.IsTrue(chainspecRegistryKey.StartsWith(ChainspecRegistryKey.KEYPREFIX));

var key = GlobalStateKey.FromString(chainspecRegistryKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is ChainspecRegistryKey);
Assert.AreEqual(chainspecRegistryKey, key.ToString());

var bytes = Hex.Decode("0d0909090909090909090909090909090909090909090909090909090909090909");
key = GlobalStateKey.FromBytes(bytes);
Assert.IsNotNull(key);
Assert.IsTrue(key is ChainspecRegistryKey);
Assert.AreEqual(chainspecRegistryKey, key.ToString());
Assert.IsTrue(key.GetBytes().SequenceEqual(bytes));
}

[Test]
public void ChecksumRegistryKeyTest()
{
const string checksumRegistryKey = "checksum-registry-0909090909090909090909090909090909090909090909090909090909090909";
Assert.IsTrue(checksumRegistryKey.StartsWith(ChecksumRegistryKey.KEYPREFIX));

var key = GlobalStateKey.FromString(checksumRegistryKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is ChecksumRegistryKey);
Assert.AreEqual(checksumRegistryKey, key.ToString());

var bytes = Hex.Decode("0e0909090909090909090909090909090909090909090909090909090909090909");
key = GlobalStateKey.FromBytes(bytes);
Assert.IsNotNull(key);
Assert.IsTrue(key is ChecksumRegistryKey);
Assert.AreEqual(checksumRegistryKey, key.ToString());
Assert.IsTrue(key.GetBytes().SequenceEqual(bytes));
}

[Test]
public void ContractsKeyTest()
{
const string contractPackageKey =
"contract-package-0909090909090909090909090909090909090909090909090909090909090909";

var key = GlobalStateKey.FromString(contractPackageKey);
Assert.IsNotNull(key);
Assert.IsTrue(key is HashKey);
}

[Test]
public void InvalidPrefixTest()
{
Expand Down Expand Up @@ -275,7 +401,7 @@ public void InvalidPrefixTest()
GlobalStateKey.FromString(invalidPrefixKey);
});
Assert.IsNotNull(ex);
Assert.IsTrue(ex.Message.StartsWith("Key not valid. Unknown key prefix."));
Assert.IsTrue(ex.Message.StartsWith("Key not valid. Unknown key prefix"));
}

[Test]
Expand Down Expand Up @@ -332,4 +458,4 @@ public void HashKeyJsonDeserializeTest()
Assert.IsTrue(ex.Message.Contains("checksum mismatch"));
}
}
}
}
5 changes: 3 additions & 2 deletions Casper.Network.SDK.Test/NctlContractTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public async Task QueryContractKeysTest()
var rpcResponse3 = await _client.QueryGlobalState(_contractPackageKey);
var contractPackageInfo = rpcResponse3.Parse().StoredValue.ContractPackage;
Assert.IsTrue(contractPackageInfo.Versions.Count > 0);

Assert.AreEqual(LockStatus.Locked, contractPackageInfo.LockStatus);

var contractWasmKey = GlobalStateKey.FromString(contractInfo.ContractWasmHash);
var rpcResponse4 = await _client.QueryGlobalState(contractWasmKey);
var contractWasmInfo = rpcResponse4.Parse().StoredValue.ContractWasm;
Expand All @@ -91,7 +92,7 @@ public async Task CallContractByNameTest()
150_000_000,
_chainName,
1, //gasPrice=1
24*3_600_000); //ttl='1day'
18*3_600_000); //ttl='18h'
deploy.Sign(_faucetKey);

var putResponse = await _client.PutDeploy(deploy);
Expand Down
Loading

0 comments on commit 3754779

Please sign in to comment.