Skip to content

Commit

Permalink
Merge pull request #117 from hyperledger/develop
Browse files Browse the repository at this point in the history
v3.5.0
  • Loading branch information
ERussel authored Nov 22, 2019
2 parents c694f3d + 486006e commit f6d120b
Show file tree
Hide file tree
Showing 23 changed files with 379 additions and 59 deletions.
4 changes: 2 additions & 2 deletions Example/IrohaExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class ViewController: UIViewController {
print("Creating new one and minting \(Constants.assetMintVolume)")

do {
let mintAmount = try IRAmountFactory.amount(fromUnsignedInteger: Constants.assetMintVolume)
let mintAmount = try IRAmountFactory.transferAmount(fromUnsignedInteger: Constants.assetMintVolume)
let transaction = try IRTransactionBuilder(creatorAccountId: self.adminAccountId)
.createAsset(self.assetId, precision: 1)
.addAssetQuantity(self.assetId, amount: mintAmount)
Expand All @@ -206,7 +206,7 @@ class ViewController: UIViewController {

private func transfer(to newAccountId: IRAccountId, amount: UInt, description: String) -> IRPromise {
do {
let amountObject = try IRAmountFactory.amount(fromUnsignedInteger: amount)
let amountObject = try IRAmountFactory.transferAmount(fromUnsignedInteger: amount)
let transaction = try IRTransactionBuilder(creatorAccountId: adminAccountId)
.transferAsset(adminAccountId,
destinationAccount: newAccountId,
Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ PODS:
- gRPC/Main (1.11.0):
- gRPC-Core (= 1.11.0)
- gRPC-RxLibrary (= 1.11.0)
- IrohaCommunication (3.4.0):
- IrohaCommunication (3.4.1):
- BoringSSL (= 10.0.3)
- gRPC-ProtoRPC (= 1.11.0)
- IrohaCrypto
Expand Down Expand Up @@ -62,11 +62,11 @@ SPEC CHECKSUMS:
gRPC-Core: 164639cd8ae18ca8b65477fafb2efbaecf4f181a
gRPC-ProtoRPC: bb5fddf3424aa4fad74d76736578a79fe40e244e
gRPC-RxLibrary: 26d53d1b1f306befd4ad4e15bd6de27839a82481
IrohaCommunication: 1519ba62909b1d8283244a6b9098b330bae2beab
IrohaCommunication: 988a6f7fe468a863486e183fb8da617519ccb94e
IrohaCrypto: 4eb85b5edbf7667b5ffcef1b5104357f18ca8e81
nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3
Protobuf: 8a9838fba8dae3389230e1b7f8c104aa32389c03

PODFILE CHECKSUM: 29089a97c3781ec366ef8266addf4289525ff849

COCOAPODS: 1.8.0
COCOAPODS: 1.8.4
5 changes: 3 additions & 2 deletions IntegrationTests/Scenarious/IRCreateAssetTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ @interface IRCreateAssetTest : IRBaseIrohaContainerTests

@implementation IRCreateAssetTest

- (void)testCreateAddSubtractQueryAsset {
- (void)testCreateAddQueryAsset {
NSError *error = nil;
id<IRAssetId> assetId = [IRAssetIdFactory assetIdWithName:@"dummycoin"
domain:self.domain
Expand All @@ -32,7 +32,8 @@ - (void)testCreateAddSubtractQueryAsset {
signatoryPublicKeys:@[self.adminPublicKey]
error:&error];

id<IRAmount> addAmount = [IRAmountFactory amountFromUnsignedInteger:200 error:&error];
id<IRTransferAmount> addAmount = [IRAmountFactory transferAmountFromUnsignedInteger:200
error:&error];

if (error) {
XCTFail();
Expand Down
131 changes: 128 additions & 3 deletions IntegrationTests/Scenarious/IRGetAssetsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ - (void)testGetAssetsInSinglePage {
signatoryPublicKeys:@[self.adminPublicKey]
error:&error];

id<IRAmount> addAmount = [IRAmountFactory amountFromUnsignedInteger:200 error:&error];
id<IRTransferAmount> addAmount = [IRAmountFactory transferAmountFromUnsignedInteger:200
error:&error];

if (error) {
XCTFail();
Expand Down Expand Up @@ -148,7 +149,8 @@ - (void)testGetAssetsInSeveralPages {
signatoryPublicKeys:@[self.adminPublicKey]
error:&error];

id<IRAmount> addAmount = [IRAmountFactory amountFromUnsignedInteger:200 error:&error];
id<IRTransferAmount> addAmount = [IRAmountFactory transferAmountFromUnsignedInteger:200
error:&error];

if (error) {
XCTFail();
Expand Down Expand Up @@ -238,7 +240,7 @@ - (void)testGetAssetsInSeveralPages {
id<IRAccountAssetsResponse> assetsResponse = result;

id<IRAccountAsset> firstAsset = [assetsResponse.accountAssets firstObject];

XCTAssertEqual(assetsResponse.totalCount, 2);
XCTAssertEqualObjects(assetsResponse.nextAssetId.identifier, secondAssetId.identifier);
XCTAssertEqualObjects(firstAsset.assetId.identifier, firstAssetId.identifier);
Expand Down Expand Up @@ -269,4 +271,127 @@ - (void)testGetAssetsInSeveralPages {
[self waitForExpectations:@[expectation] timeout:120.0];
}

- (void)testCreateTransferThenFetchAssetWithZeroBalance {
NSError *error = nil;
id<IRAssetId> assetId = [IRAssetIdFactory assetIdWithName:@"dummycoin"
domain:self.domain
error:&error];

if (error) {
XCTFail();
return;
}

id<IRAccountId> newAccount = [IRAccountIdFactory accountIdWithName:@"new"
domain:self.domain
error:&error];

id<IRCryptoKeypairProtocol> newKeypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair];

if (error) {
XCTFail();
return;
}

UInt32 assetPrecision = 2;
IRTransactionBuilder *assetTransactionBuilder = [IRTransactionBuilder
builderWithCreatorAccountId:self.adminAccountId];
assetTransactionBuilder = [assetTransactionBuilder createAsset:assetId precision:assetPrecision];

id<IRTransaction> assetTransaction = [[assetTransactionBuilder build:&error]
signedWithSignatories:@[self.adminSigner]
signatoryPublicKeys:@[self.adminPublicKey]
error:&error];

id<IRTransferAmount> addAmount = [IRAmountFactory transferAmountFromUnsignedInteger:200
error:&error];

if (error) {
XCTFail();
return;
}

XCTestExpectation *expectation = [XCTestExpectation new];

[self.iroha executeTransaction:assetTransaction].onThen(^IRPromise * _Nullable (id result) {
return [IRRepeatableStatusStream onTransactionStatus:IRTransactionStatusCommitted
withHash:result
from:self.iroha];
}).onThen(^IRPromise * _Nullable (id result) {
IRTransactionBuilder *transactionBuilder = [IRTransactionBuilder builderWithCreatorAccountId:self.adminAccountId];
transactionBuilder = [transactionBuilder createAccount:newAccount
publicKey:newKeypair.publicKey];
transactionBuilder = [transactionBuilder addAssetQuantity:assetId
amount:addAmount];
transactionBuilder = [transactionBuilder transferAsset:self.adminAccountId
destinationAccount:newAccount
assetId:assetId
description:@""
amount:addAmount];

NSError *error = nil;
id<IRTransaction> transaction = [[transactionBuilder build:&error]
signedWithSignatories:@[self.adminSigner]
signatoryPublicKeys:@[self.adminPublicKey] error:&error];

if (error) {
return [IRPromise promiseWithResult:error];
}

return [self.iroha executeTransaction:transaction];
}).onThen(^IRPromise * _Nullable (id result) {
return [IRRepeatableStatusStream onTransactionStatus:IRTransactionStatusCommitted
withHash:result
from:self.iroha];
}).onThen(^IRPromise * _Nullable (id result) {
IRQueryBuilder *queryBuilder = [IRQueryBuilder builderWithCreatorAccountId:self.adminAccountId];
id<IRAssetPagination> pagination = [IRAssetPaginationFactory assetPagination:1 startingAssetId:assetId];
queryBuilder = [queryBuilder getAccountAssets:self.adminAccountId pagination:pagination];

NSError *error = nil;
id<IRQueryRequest> request = [[queryBuilder build:&error] signedWithSignatory:self.adminSigner
signatoryPublicKey:self.adminPublicKey
error:&error];

if (error) {
return [IRPromise promiseWithResult:error];
}

return [self.iroha executeQueryRequest:request];
}).onThen(^IRPromise * _Nullable (id result) {
NSLog(@"%@", result);
if ([result conformsToProtocol:@protocol(IRAccountAssetsResponse)]) {
id<IRAccountAssetsResponse> assetsResponse = result;

id<IRAccountAsset> asset = [assetsResponse.accountAssets firstObject];

XCTAssertEqualObjects(asset.assetId.identifier, assetId.identifier);
XCTAssertEqual(asset.balance.value.intValue, 0);

return [IRPromise promiseWithResult:nil];
} else {
NSString *message = [NSString stringWithFormat:@"Invalid get assets response %@", NSStringFromClass([result class])];
NSError *error = [NSError errorWithDomain:@"co.jp.getassetstest"
code:0
userInfo:@{NSLocalizedDescriptionKey: message}];

return [IRPromise promiseWithResult:error];
}
}).onThen(^IRPromise * _Nullable (id result) {
NSLog(@"%@", result);

[expectation fulfill];

return nil;
}).onError(^IRPromise * _Nullable (NSError *error) {
XCTFail();
NSLog(@"%@", error);

[expectation fulfill];
return nil;
});

[self waitForExpectations:@[expectation] timeout:120.0];;
}

@end
2 changes: 1 addition & 1 deletion IrohaCommunication.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'IrohaCommunication'
s.version = '3.4.1'
s.version = '3.5.0'
s.summary = 'Helper classes to use for communication with Iroha blockchain.'

s.homepage = 'https://github.com/hyperledger/iroha-ios'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
@interface IRAddAssetQuantity : NSObject<IRAddAssetQuantity, IRProtobufTransformable>

- (nonnull instancetype)initWithAssetId:(nonnull id<IRAssetId>)assetId
amount:(nonnull id<IRAmount>)amount;
amount:(nonnull id<IRTransferAmount>)amount;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ @implementation IRAddAssetQuantity
@synthesize amount = _amount;

- (nonnull instancetype)initWithAssetId:(nonnull id<IRAssetId>)assetId
amount:(nonnull id<IRAmount>)amount {
amount:(nonnull id<IRTransferAmount>)amount {
if (self = [super init]) {
_assetId = assetId;
_amount = amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
@interface IRSubtractAssetQuantity : NSObject<IRSubtractAssetQuantity, IRProtobufTransformable>

- (nonnull instancetype)initWithAssetId:(nonnull id<IRAssetId>)assetId
amount:(nonnull id<IRAmount>)amount;
amount:(nonnull id<IRTransferAmount>)amount;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ @implementation IRSubtractAssetQuantity
@synthesize amount = _amount;

- (nonnull instancetype)initWithAssetId:(nonnull id<IRAssetId>)assetId
amount:(nonnull id<IRAmount>)amount {
amount:(nonnull id<IRTransferAmount>)amount {

if (self = [super init]) {
_assetId = assetId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
destinationAccountId:(nonnull id<IRAccountId>)destinationAccountId
assetId:(nonnull id<IRAssetId>)assetId
transferDescription:(nonnull NSString *)transferDescription
amount:(nonnull id<IRAmount>)amount;
amount:(nonnull id<IRTransferAmount>)amount;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ - (nonnull instancetype)initWithSourceAccountId:(nonnull id<IRAccountId>)sourceA
destinationAccountId:(nonnull id<IRAccountId>)destinationAccountId
assetId:(nonnull id<IRAssetId>)assetId
transferDescription:(nonnull NSString *)transferDescription
amount:(nonnull id<IRAmount>)amount {
amount:(nonnull id<IRTransferAmount>)amount {

if (self = [super init]) {
_sourceAccountId = sourceAccountId;
Expand Down
12 changes: 6 additions & 6 deletions IrohaCommunication/Classes/Private/Models/IRCommand+Proto.m
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ @implementation IRCommandProtoFactory

NSString *transferDescription = pbCommand.description_p ? pbCommand.description_p : @"";

id<IRAmount> amount = [IRAmountFactory amountFromString:pbCommand.amount
error:error];
id<IRTransferAmount> amount = [IRAmountFactory transferAmountFromString:pbCommand.amount
error:error];

if (!amount) {
return nil;
Expand Down Expand Up @@ -407,8 +407,8 @@ @implementation IRCommandProtoFactory
return nil;
}

id<IRAmount> amount = [IRAmountFactory amountFromString:pbCommand.amount
error:error];
id<IRTransferAmount> amount = [IRAmountFactory transferAmountFromString:pbCommand.amount
error:error];

if (!amount) {
return nil;
Expand Down Expand Up @@ -475,8 +475,8 @@ @implementation IRCommandProtoFactory
return nil;
}

id<IRAmount> amount = [IRAmountFactory amountFromString:pbCommand.amount
error:error];
id<IRTransferAmount> amount = [IRAmountFactory transferAmountFromString:pbCommand.amount
error:error];

if (!amount) {
return nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ typedef NS_ENUM(NSUInteger, IRTransactionBuilderError) {
+ (nonnull instancetype)builderWithCreatorAccountId:(nonnull id<IRAccountId>)creator;

- (nonnull instancetype)addAssetQuantity:(nonnull id<IRAssetId>)assetId
amount:(nonnull id<IRAmount>)amount;
amount:(nonnull id<IRTransferAmount>)amount;

- (nonnull instancetype)subtractAssetQuantity:(nonnull id<IRAssetId>)assetId
amount:(nonnull id<IRAmount>)amount;
amount:(nonnull id<IRTransferAmount>)amount;

- (nonnull instancetype)addPeer:(nonnull id<IRAddress>)address
publicKey:(nonnull id<IRPublicKeyProtocol>)publicKey;
Expand Down Expand Up @@ -77,7 +77,7 @@ typedef NS_ENUM(NSUInteger, IRTransactionBuilderError) {
destinationAccount:(nonnull id<IRAccountId>)destinationAccountId
assetId:(nonnull id<IRAssetId>)assetId
description:(nonnull NSString *)transferDescription
amount:(nonnull id<IRAmount>)amount;
amount:(nonnull id<IRTransferAmount>)amount;

- (nonnull instancetype)removePeer:(nonnull id<IRPublicKeyProtocol>)peerKey;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ + (nonnull instancetype)builderWithCreatorAccountId:(nonnull id<IRAccountId>)cre
}

- (nonnull instancetype)addAssetQuantity:(nonnull id<IRAssetId>)assetId
amount:(nonnull id<IRAmount>)amount {
amount:(nonnull id<IRTransferAmount>)amount {

IRAddAssetQuantity *command = [[IRAddAssetQuantity alloc] initWithAssetId:assetId
amount:amount];
Expand All @@ -53,7 +53,7 @@ - (nonnull instancetype)addAssetQuantity:(nonnull id<IRAssetId>)assetId
}

- (nonnull instancetype)subtractAssetQuantity:(nonnull id<IRAssetId>)assetId
amount:(nonnull id<IRAmount>)amount {
amount:(nonnull id<IRTransferAmount>)amount {

IRSubtractAssetQuantity *command = [[IRSubtractAssetQuantity alloc] initWithAssetId:assetId
amount:amount];
Expand Down Expand Up @@ -212,7 +212,7 @@ - (nonnull instancetype)transferAsset:(nonnull id<IRAccountId>)sourceAccountId
destinationAccount:(nonnull id<IRAccountId>)destinationAccountId
assetId:(nonnull id<IRAssetId>)assetId
description:(nonnull NSString *)transferDescription
amount:(nonnull id<IRAmount>)amount {
amount:(nonnull id<IRTransferAmount>)amount {

IRTransferAsset *command = [[IRTransferAsset alloc] initWithSourceAccountId:sourceAccountId
destinationAccountId:destinationAccountId
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#import <Foundation/Foundation.h>
#import "IRAmount.h"

@interface NSDecimalNumber (IRAmount)

+ (nullable NSDecimalNumber *)decimalNumberWithAmountValue:(nonnull NSString *)value;
+ (nullable NSDecimalNumber *)decimalNumberWithAmount:(nonnull id<IRAmount>)amount;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#import "NSDecimalNumber+IRAmount.h"

static NSString * const DECIMAL_SEPARATOR = @".";

@implementation NSDecimalNumber (IRAmount)

+ (nullable NSDecimalNumber *)decimalNumberWithAmountValue:(nonnull NSString *)value {
return [NSDecimalNumber decimalNumberWithString:value
locale:@{NSLocaleDecimalSeparator: DECIMAL_SEPARATOR}];
}

+ (nullable NSDecimalNumber *)decimalNumberWithAmount:(id<IRAmount>)amount {
return [NSDecimalNumber decimalNumberWithAmountValue:amount.value];
}

@end
Loading

0 comments on commit f6d120b

Please sign in to comment.