-
Notifications
You must be signed in to change notification settings - Fork 3
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 #55 from Concordium/fix-grpc-account-conversion
Fix issue when converting from gRPC Address
- Loading branch information
Showing
7 changed files
with
135 additions
and
53 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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Concordium.Sdk.Transactions; | ||
using Concordium.Sdk.Types; | ||
using Concordium.Sdk.Wallets; | ||
using FluentAssertions; | ||
using Xunit.Abstractions; | ||
|
||
namespace Concordium.Sdk.Tests.IntegrationTests.Types; | ||
|
||
[Trait("Category", "IntegrationTests")] | ||
[Collection("Using Wallet")] | ||
public sealed class RejectReasonTests : Tests | ||
{ | ||
private const int Timeout = 120_000; | ||
public RejectReasonTests(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
|
||
[Fact(Timeout = Timeout)] | ||
public async Task WhenTransferWithInsufficientAmount_ThenReject() | ||
{ | ||
// Arrange | ||
using var cts = new CancellationTokenSource(Timeout); | ||
|
||
var filePath = this.GetString("walletPath"); | ||
var walletData = await File.ReadAllTextAsync(filePath, cts.Token); | ||
var account = WalletAccount.FromWalletKeyExportFormat(walletData); | ||
var sender = account.AccountAddress; | ||
|
||
var to = this.GetString("transferTo"); | ||
var receiver = AccountAddress.From(to); | ||
|
||
var toBigTransfer = new Transfer(CcdAmount.FromMicroCcd(ulong.MaxValue), receiver); | ||
|
||
// Act | ||
var txHash = await this.Transfer(account, sender, toBigTransfer, cts.Token); | ||
var finalized = await this.AwaitFinalization(txHash, cts.Token); | ||
|
||
// Assert | ||
finalized.State.Summary.Details.Should().BeOfType<AccountTransactionDetails>(); | ||
var details = finalized.State.Summary.Details as AccountTransactionDetails; | ||
details!.Effects.Should().BeOfType<None>(); | ||
var none = details.Effects as None; | ||
none!.RejectReason.Should().BeOfType<AmountTooLarge>(); | ||
var amountToLarge = none.RejectReason as AmountTooLarge; | ||
amountToLarge!.Address.Should().BeOfType<AccountAddress>(); | ||
} | ||
} |
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,37 @@ | ||
using System; | ||
using Concordium.Grpc.V2; | ||
using Concordium.Sdk.Types; | ||
using FluentAssertions; | ||
using Google.Protobuf; | ||
using Xunit; | ||
using AccountAddress = Concordium.Sdk.Types.AccountAddress; | ||
|
||
namespace Concordium.Sdk.Tests.UnitTests.Types; | ||
|
||
public sealed class AddressTests | ||
{ | ||
[Fact] | ||
public void WhenGivenGrpcAccountAddress_ThenMap() | ||
{ | ||
// Arrange | ||
const string expected = "TIDFSgXWdUVHEOXdeTONB5WGRL9mN8JdEHjvgOThaIE="; | ||
var fromBase64 = ByteString.FromBase64(expected); | ||
|
||
var address = new Address(new Address | ||
{ | ||
Account = new Grpc.V2.AccountAddress | ||
{ | ||
Value = fromBase64 | ||
} | ||
}); | ||
|
||
// Act | ||
var from = AddressFactory.From(address); | ||
|
||
// Assert | ||
from.Should().BeOfType<AccountAddress>(); | ||
var accountAddress = from as AccountAddress; | ||
var actual = Convert.ToBase64String(accountAddress!.AsSpan()); | ||
actual.Should().Be(expected); | ||
} | ||
} |