|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2017 American Express Travel Related Services Company, Inc. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
|
15
|
|
|
* or implied. See the License for the specific language governing |
|
16
|
|
|
* permissions and limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
declare(strict_types=1); |
|
20
|
|
|
|
|
21
|
|
|
namespace AmericanExpressIntegrationTest\HyperledgerFabricClient\Chaincode; |
|
22
|
|
|
|
|
23
|
|
|
use AmericanExpress\HyperledgerFabricClient\Channel\ChannelProviderInterface; |
|
24
|
|
|
use AmericanExpress\HyperledgerFabricClient\ClientFactory; |
|
25
|
|
|
use AmericanExpress\HyperledgerFabricClient\Config\ClientConfigFactory; |
|
26
|
|
|
use AmericanExpress\HyperledgerFabricClient\Config\ClientConfigInterface; |
|
27
|
|
|
use AmericanExpress\HyperledgerFabricClient\Peer\PeerFactory; |
|
28
|
|
|
use AmericanExpress\HyperledgerFabricClient\Transaction\TransactionOptions; |
|
29
|
|
|
use PHPUnit\Framework\TestCase; |
|
30
|
|
|
|
|
31
|
|
|
class ChaincodeTest extends TestCase |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var ClientConfigInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private static $config; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var ChannelProviderInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
private $channelProvider; |
|
42
|
|
|
|
|
43
|
|
|
public static function setUpBeforeClass() |
|
44
|
|
|
{ |
|
45
|
|
|
self::$config = ClientConfigFactory::fromFile( |
|
46
|
|
|
new \SplFileObject(__DIR__ . '/../../config.php') |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
protected function setUp() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->channelProvider = ClientFactory::fromConfig(self::$config); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Demonstrates the most basic usage, where the client has only one peer per org, |
|
57
|
|
|
* and selects the first org by default. |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testChainCodeEntityQuery() |
|
60
|
|
|
{ |
|
61
|
|
|
$responses = $this->channelProvider->getChannel('foo') |
|
62
|
|
|
->getChaincode('example_cc') |
|
63
|
|
|
->invoke('query', 'a'); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
self::assertCount(1, $responses->getProposalResponses()); |
|
66
|
|
|
self::assertCount(0, $responses->getExceptions()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Demonstrates extended usage of the client, where an org is explicitly specified per client |
|
71
|
|
|
* and the peer is explicitly specified at query-time via overridable transaction-options. |
|
72
|
|
|
*/ |
|
73
|
|
|
public function testQueryChaincodeWithCustomPeer() |
|
74
|
|
|
{ |
|
75
|
|
|
$peer = (new PeerFactory())->fromArray([ |
|
76
|
|
|
'requests' => 'localhost:7051', |
|
77
|
|
|
]); |
|
78
|
|
|
|
|
79
|
|
|
$options = new TransactionOptions([ |
|
80
|
|
|
'peers' => [$peer], |
|
81
|
|
|
]); |
|
82
|
|
|
|
|
83
|
|
|
$responses = ClientFactory::fromConfig(self::$config, 'peerOrg1') |
|
84
|
|
|
->getChannel('foo') |
|
85
|
|
|
->getChaincode([ |
|
86
|
|
|
'name' => 'example_cc', |
|
87
|
|
|
'version' => '1', |
|
88
|
|
|
'path' => 'github.com/example_cc' |
|
89
|
|
|
]) |
|
90
|
|
|
->invoke('query', 'a', $options); |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
self::assertCount(1, $responses->getProposalResponses()); |
|
93
|
|
|
self::assertCount(0, $responses->getExceptions()); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|