Skip to content

Commit

Permalink
Format and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
schwartz-concordium committed Nov 3, 2023
1 parent e25cd73 commit f41d501
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased changes
- Added
- Deserialization from module schema
- Contract entrypoint messages
- Contract events
- Module schema
- New GRPC-endpoints: `GetBlocks`, `GetFinalizedBlocks`, `GetBranches`, `GetAncestors`, `GetBlockPendingUpdates`
- Helpers to get contract name on `ReceiveName` and `ContractName` and entrypoint on `ReceiveName`.

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/InteropBindingException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static InteropBindingException Create(string? message) =>
message != null ? new InteropBindingException(message) : Empty();

private InteropBindingException(string message) : base(message)
{}
{ }

private static InteropBindingException Empty() => new(EmptyErrorMessage);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Interop/InteropBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ private static void FreeIfNonzero(IntPtr ptr)
/// A C# layout which compiled to a C interpretable structure. This is used as an optional parameter.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct FFIByteOption
internal readonly struct FFIByteOption
{
internal byte t { get; private init; }

Check warning on line 137 in src/Interop/InteropBinding.cs

View workflow job for this annotation

GitHub Actions / build-test-format

Naming rule violation: These words must begin with upper case characters: t
/// <summary>
/// 1 is interpreted as true. <see cref="Boolean"/> are not used since it isn't a blittable type.
/// 1 is interpreted as true. <see cref="bool"/> are not used since it isn't a blittable type.
/// </summary>
/// <remarks>
/// <see href="https://learn.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types">Blittable and Non-Blittable Types</see>
Expand Down
1 change: 0 additions & 1 deletion src/Types/RejectReason.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Application.Exceptions;
using Concordium.Sdk.Exceptions;
using Concordium.Sdk.Interop;

namespace Concordium.Sdk.Types;

Expand Down
4 changes: 2 additions & 2 deletions src/Types/VersionedModuleSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract record VersionedModuleSource
protected VersionedModuleSource(byte[] source)
{
this.Source = source;
this._module = new Lazy<Module>(this.GetWasmModule);
this._module = new Lazy<Module>(this.GetWasmModule);
}

/// <summary>
Expand Down Expand Up @@ -103,7 +103,7 @@ public sealed record ModuleV0(byte[] Source) : VersionedModuleSource(Source)
internal static ModuleV0 From(Grpc.V2.VersionedModuleSource.Types.ModuleSourceV0 moduleSourceV0) =>
new(moduleSourceV0.Value.ToByteArray());

private protected override (byte[]? Schema, ModuleSchemaVersion SchemaVersion)? ExtractSchemaFromWebAssemblyModule(WebAssembly.Module module)
private protected override (byte[]? Schema, ModuleSchemaVersion SchemaVersion)? ExtractSchemaFromWebAssemblyModule(Module module)
{
if (GetSchemaFromWasmCustomSection(module, "concordium-schema", out var moduleV0SchemaUndefined))
{
Expand Down
4 changes: 2 additions & 2 deletions tests/UnitTests/Interop/InteropBindingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task WhenSchemaDisplay_ThenReturnSchema()
var schema = (await File.ReadAllTextAsync("./Data/cis2_wCCD_sub")).Trim();

// Act
var message = InteropBinding.SchemaDisplay(schema, ModuleSchemaVersion.Undefined);
var message = InteropBinding.SchemaDisplay(schema, ModuleSchemaVersion.Undefined);

// Assert
await Verifier.Verify(message)
Expand All @@ -51,7 +51,7 @@ public async Task WhenDisplayReceiveParam_ThenReturnParams()
const string value = "005f8b99a3ea8089002291fd646554848b00e7a0cd934e5bad6e6e93a4d4f4dc790000";

// Act
var message = InteropBinding.GetReceiveContractParameter(schema, contractName, entrypoint, value,null);
var message = InteropBinding.GetReceiveContractParameter(schema, contractName, entrypoint, value, null);

// Assert
await Verifier.Verify(message)
Expand Down
2 changes: 1 addition & 1 deletion tests/UnitTests/Types/ContractEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void WhenGetDeserializedEventsFromUpdated_ThenReturnParsedEvents()
var schema = File.ReadAllText("./Data/cis2_wCCD_sub").Trim();
const string contractName = "cis2_wCCD";
const string eventMessage = "fe00c0843d005f8b99a3ea8089002291fd646554848b00e7a0cd934e5bad6e6e93a4d4f4dc79";
const string expectedEvent = "{\"Mint\":{\"amount\":\"1000000\",\"owner\":{\"Account\":[\"3fpkgmKcGDKGgsDhUQEBAQXbFZJQw97JmbuhzmvujYuG1sQxtV\"]},\"token_id\":\"\"}}";
const string expectedEvent = /*lang=json,strict*/ "{\"Mint\":{\"amount\":\"1000000\",\"owner\":{\"Account\":[\"3fpkgmKcGDKGgsDhUQEBAQXbFZJQw97JmbuhzmvujYuG1sQxtV\"]},\"token_id\":\"\"}}";
var versionedModuleSchema = new VersionedModuleSchema(schema, ModuleSchemaVersion.Undefined);
var contractEvent = new ContractEvent(Convert.FromHexString(eventMessage));

Expand Down
6 changes: 3 additions & 3 deletions tests/UnitTests/Types/ContractInitializedEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public void WhenGetDeserializedEventsFromContractInitializedEvent_ThenReturnPars
var schema = File.ReadAllText("./Data/cis2_wCCD_sub").Trim();
const string contractName = "cis2_wCCD";
const string eventMessage = "fe00c0843d005f8b99a3ea8089002291fd646554848b00e7a0cd934e5bad6e6e93a4d4f4dc79";
const string expectedEvent = "{\"Mint\":{\"amount\":\"1000000\",\"owner\":{\"Account\":[\"3fpkgmKcGDKGgsDhUQEBAQXbFZJQw97JmbuhzmvujYuG1sQxtV\"]},\"token_id\":\"\"}}";
const string expectedEvent = /*lang=json,strict*/ "{\"Mint\":{\"amount\":\"1000000\",\"owner\":{\"Account\":[\"3fpkgmKcGDKGgsDhUQEBAQXbFZJQw97JmbuhzmvujYuG1sQxtV\"]},\"token_id\":\"\"}}";
_ = ContractName.TryParse($"init_{contractName}", out var result);
var versionedModuleSchema = new VersionedModuleSchema(schema, ModuleSchemaVersion.Undefined);

var contractInitializedEvent = new ContractInitializedEvent(
ContractVersion.V0,
new ModuleReference(Convert.ToHexString(new byte[Hash.BytesLength])),
new ContractAddress(1,0),
new ContractAddress(1, 0),
CcdAmount.Zero,
result.ContractName!,
new List<ContractEvent>{new(Convert.FromHexString(eventMessage))});
new List<ContractEvent> { new(Convert.FromHexString(eventMessage)) });

// Act
var events = contractInitializedEvent.GetDeserializedEvents(versionedModuleSchema);
Expand Down
20 changes: 10 additions & 10 deletions tests/UnitTests/Types/ContractTraceElementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public void WhenGetDeserializedMessageFromUpdated_ThenReturnParsedMessage()
const string contractName = "cis2_wCCD";
const string entrypoint = "wrap";
const string message = "005f8b99a3ea8089002291fd646554848b00e7a0cd934e5bad6e6e93a4d4f4dc790000";
const string expectedMessage = "{\"data\":\"\",\"to\":{\"Account\":[\"3fpkgmKcGDKGgsDhUQEBAQXbFZJQw97JmbuhzmvujYuG1sQxtV\"]}}";
const string expectedMessage = /*lang=json,strict*/ "{\"data\":\"\",\"to\":{\"Account\":[\"3fpkgmKcGDKGgsDhUQEBAQXbFZJQw97JmbuhzmvujYuG1sQxtV\"]}}";
_ = ReceiveName.TryParse($"{contractName}.{entrypoint}", out var result);
var versionedModuleSchema = new VersionedModuleSchema(schema, ModuleSchemaVersion.Undefined);

var updated = new Updated(
ContractVersion.V0,
new ContractAddress(1,0),
new ContractAddress(1,0),
new ContractAddress(1, 0),
new ContractAddress(1, 0),
CcdAmount.Zero,
new Parameter(Convert.FromHexString(message)),
result.ReceiveName!,
Expand All @@ -45,18 +45,18 @@ public void WhenGetDeserializedEventsFromUpdated_ThenReturnParsedEvents()
const string contractName = "cis2_wCCD";
const string entrypoint = "wrap";
const string eventMessage = "fe00c0843d005f8b99a3ea8089002291fd646554848b00e7a0cd934e5bad6e6e93a4d4f4dc79";
const string expectedEvent = "{\"Mint\":{\"amount\":\"1000000\",\"owner\":{\"Account\":[\"3fpkgmKcGDKGgsDhUQEBAQXbFZJQw97JmbuhzmvujYuG1sQxtV\"]},\"token_id\":\"\"}}";
const string expectedEvent = /*lang=json,strict*/ "{\"Mint\":{\"amount\":\"1000000\",\"owner\":{\"Account\":[\"3fpkgmKcGDKGgsDhUQEBAQXbFZJQw97JmbuhzmvujYuG1sQxtV\"]},\"token_id\":\"\"}}";
_ = ReceiveName.TryParse($"{contractName}.{entrypoint}", out var result);
var versionedModuleSchema = new VersionedModuleSchema(schema, ModuleSchemaVersion.Undefined);

var updated = new Updated(
ContractVersion.V0,
new ContractAddress(1,0),
new ContractAddress(1,0),
new ContractAddress(1, 0),
new ContractAddress(1, 0),
CcdAmount.Zero,
new Parameter(Array.Empty<byte>()),
result.ReceiveName!,
new List<ContractEvent>{new(Convert.FromHexString(eventMessage))});
new List<ContractEvent> { new(Convert.FromHexString(eventMessage)) });

// Act
var events = updated.GetDeserializedEvents(versionedModuleSchema);
Expand All @@ -72,12 +72,12 @@ public void WhenGetDeserializedEventsFromInterrupted_ThenReturnParsedEvents()
var schema = File.ReadAllText("./Data/cis2_wCCD_sub").Trim();
const string contractName = "cis2_wCCD";
const string eventMessage = "fe00c0843d005f8b99a3ea8089002291fd646554848b00e7a0cd934e5bad6e6e93a4d4f4dc79";
const string expectedEvent = "{\"Mint\":{\"amount\":\"1000000\",\"owner\":{\"Account\":[\"3fpkgmKcGDKGgsDhUQEBAQXbFZJQw97JmbuhzmvujYuG1sQxtV\"]},\"token_id\":\"\"}}";
const string expectedEvent = /*lang=json,strict*/ "{\"Mint\":{\"amount\":\"1000000\",\"owner\":{\"Account\":[\"3fpkgmKcGDKGgsDhUQEBAQXbFZJQw97JmbuhzmvujYuG1sQxtV\"]},\"token_id\":\"\"}}";
var versionedModuleSchema = new VersionedModuleSchema(schema, ModuleSchemaVersion.Undefined);

var interrupted = new Interrupted(
new ContractAddress(1,0),
new List<ContractEvent>{new(Convert.FromHexString(eventMessage))});
new ContractAddress(1, 0),
new List<ContractEvent> { new(Convert.FromHexString(eventMessage)) });

// Act
var events = interrupted.GetDeserializedEvents(versionedModuleSchema, contractName);
Expand Down
4 changes: 2 additions & 2 deletions tests/UnitTests/Types/RejectReasonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public void WhenGetDeserializedEventsRejectedReceive_ThenReturnParsedMessage()
const string contractName = "cis2_wCCD";
const string entrypoint = "wrap";
const string message = "005f8b99a3ea8089002291fd646554848b00e7a0cd934e5bad6e6e93a4d4f4dc790000";
const string expectedMessage = "{\"data\":\"\",\"to\":{\"Account\":[\"3fpkgmKcGDKGgsDhUQEBAQXbFZJQw97JmbuhzmvujYuG1sQxtV\"]}}";
const string expectedMessage = /*lang=json,strict*/ "{\"data\":\"\",\"to\":{\"Account\":[\"3fpkgmKcGDKGgsDhUQEBAQXbFZJQw97JmbuhzmvujYuG1sQxtV\"]}}";
_ = ReceiveName.TryParse($"{contractName}.{entrypoint}", out var result);
var versionedModuleSchema = new VersionedModuleSchema(schema, ModuleSchemaVersion.Undefined);

var rejectedReceive = new RejectedReceive(
-1,
new ContractAddress(1,0),
new ContractAddress(1, 0),
result.ReceiveName!,
new Parameter(Convert.FromHexString(message)));

Expand Down
2 changes: 1 addition & 1 deletion tests/UnitTests/Types/VersionedModuleSourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class VersionedModuleSourceTests
[InlineData("cis2-wccd-embedded-schema-v1-versioned.wasm.v1", ModuleSchemaVersion.Undefined, true, 1)]
public async Task WhenCreateModuleSchema_ThenParseWithCorrectVersion(string fileName, ModuleSchemaVersion version, bool trim, int moduleVersion)
{
var bytes = (await File.ReadAllBytesAsync($"./Data/{fileName}"));
var bytes = await File.ReadAllBytesAsync($"./Data/{fileName}");
if (trim)
{
bytes = bytes[8..];
Expand Down

0 comments on commit f41d501

Please sign in to comment.