/ ko / learn / local-two-client-test.md
local-two-client-test.md
  1  # Codex 두 클라이언트 테스트
  2  
  3  두 클라이언트 테스트는 설정을 확인하고 Codex API에 익숙해지기 위해 수행할 수 있는 수동 테스트입니다. 이 단계들은 두 개의 노드를 실행하고 연결하여 하나에 파일을 업로드한 다음 다른 노드에서 해당 파일을 다운로드하는 과정을 안내합니다. 이 테스트에는 마켓플레이스 기능을 사용할 수 있도록 로컬 블록체인 노드를 실행하는 것도 포함됩니다.
  4  
  5  ## Prerequisite
  6  
  7  Make sure you have [built the client](/learn/build) or obtained [compiled binary](/learn/quick-start#get-codex-binary).
  8  
  9  ## Steps
 10  
 11  ### 0. Setup blockchain node (optional)
 12  
 13  You need to have installed NodeJS and npm in order to spinup a local blockchain node.
 14  
 15  Go to directory `vendor/codex-contracts-eth` and run these two commands:
 16  ```
 17  npm ci
 18  npm start
 19  ```
 20  
 21  This will launch a local Ganache blockchain.
 22  
 23  ### 1. Launch Node #1
 24  
 25  Open a terminal and run:
 26  - Mac/Linux:
 27    ```shell
 28     codex \
 29       --data-dir="$(pwd)/Data1" \
 30       --api-port=8080 \
 31       --disc-port=8090 \
 32       --listen-addrs="/ip4/127.0.0.1/tcp/8070"
 33     ```
 34  - Windows:
 35    ```batch
 36    codex.exe ^
 37      --data-dir="Data1" ^
 38      --api-port=8080 ^
 39      --disc-port=8090 ^
 40      --listen-addrs="/ip4/127.0.0.1/tcp/8070"
 41    ```
 42  
 43  Optionally, if you want to use the Marketplace blockchain functionality, you need to also include these flags: `--persistence --eth-account=<account>`, where `account` can be one following:
 44  
 45    - `0x70997970C51812dc3A010C7d01b50e0d17dc79C8`
 46    - `0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC`
 47    - `0x90F79bf6EB2c4f870365E785982E1f101E93b906`
 48    - `0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65`
 49  
 50  **For each node use a different account!**
 51  
 52  | Argument       | Description                                                           |
 53  |----------------|-----------------------------------------------------------------------|
 54  | `data-dir`     | We specify a relative path where the node will store its data.        |
 55  | `listen-addrs` | Multiaddress where the node will accept connections from other nodes. |
 56  | `api-port`     | Port on localhost where the node will expose its API.                 |
 57  | `disc-port`    | Port the node will use for its discovery service.                     |
 58  | `persistence`  | Enables Marketplace functionality. Requires a blockchain connection.  |
 59  | `eth-account`  | Defines which blockchain account the node should use.                 |
 60  
 61  Codex uses sane defaults for most of its arguments. Here we specify some explicitly for the purpose of this walk-through.
 62  
 63  ### 2. Sign of life
 64  
 65  Run the command :
 66  
 67  ```bash
 68  curl -X GET http://127.0.0.1:8080/api/codex/v1/debug/info
 69  ```
 70  
 71  This GET request will return the node's debug information. The response will be in JSON and should look like:
 72  
 73  ```json
 74  {
 75    "id": "16Uiu2HAmJ3TSfPnrJNedHy2DMsjTqwBiVAQQqPo579DuMgGxmG99",
 76    "addrs": [
 77      "/ip4/127.0.0.1/tcp/8070"
 78    ],
 79    "repo": "/Users/user/projects/nim-codex/Data1",
 80    "spr": "spr:CiUIAhIhA1AL2J7EWfg7x77iOrR9YYBisY6CDtU2nEhuwDaQyjpkEgIDARo8CicAJQgCEiEDUAvYnsRZ-DvHvuI6tH1hgGKxjoIO1TacSG7ANpDKOmQQ2MWasAYaCwoJBH8AAAGRAh-aKkYwRAIgB2ooPfAyzWEJDe8hD2OXKOBnyTOPakc4GzqKqjM2OGoCICraQLPWf0oSEuvmSroFebVQx-3SDtMqDoIyWhjq1XFF",
 81    "announceAddresses": [
 82      "/ip4/127.0.0.1/tcp/8070"
 83    ],
 84    "table": {
 85      "localNode": {
 86        "nodeId": "f6e6d48fa7cd171688249a57de0c1aba15e88308c07538c91e1310c9f48c860a",
 87        "peerId": "16Uiu2HAmJ3TSfPnrJNedHy2DMsjTqwBiVAQQqPo579DuMgGxmG99",
 88        "record": "...",
 89        "address": "0.0.0.0:8090",
 90        "seen": false
 91      },
 92      "nodes": []
 93    },
 94    "codex": {
 95      "version": "untagged build",
 96      "revision": "b3e626a5"
 97    }
 98  }
 99  ```
100  
101  | Field               | Description                                                                              |
102  | ------------------- | ---------------------------------------------------------------------------------------- |
103  | `id`                | Id of the node. Also referred to as 'peerId'.                                            |
104  | `addrs`             | Multiaddresses currently open to accept connections from other nodes.                    |
105  | `repo`              | Path of this node's data folder.                                                         |
106  | `spr`               | Signed Peer Record, encoded information about this node and its location in the network. |
107  | `announceAddresses` | Multiaddresses used for annoucning this node                                             |
108  | `table`             | Table of nodes present in the node's DHT                                                 |
109  | `codex`             | Codex version information                                                                |
110  
111  ### 3. Launch Node #2
112  
113  We will need the signed peer record (SPR) from the first node that you got in the previous step.
114  
115  Replace `<SPR HERE>` in the following command with the SPR returned from the previous command, note that it should include the `spr:` at the beginning.
116  
117  Open a new terminal and run:
118  - Mac/Linux:
119    ```shell
120    codex \
121      --data-dir="$(pwd)/Data2" \
122      --api-port=8081 \
123      --disc-port=8091 \
124      --listen-addrs=/ip4/127.0.0.1/tcp/8071 \
125      --bootstrap-node=<SPR HERE>
126    ```
127  - Windows:
128    ```
129    codex.exe ^
130      --data-dir="Data2" ^
131      --api-port=8081 ^
132      --disc-port=8091 ^
133      --listen-addrs=/ip4/127.0.0.1/tcp/8071 ^
134      --bootstrap-node=<SPR HERE>
135    ```
136  
137  Alternatively on Mac, Linux, or MSYS2 and a recent Codex binary you can run it in one command like:
138  
139  ```shell
140  codex \
141    --data-dir="$(pwd)/Data2" \
142    --api-port=8081 \
143    --disc-port=8091 \
144    --listen-addrs=/ip4/127.0.0.1/tcp/8071 \
145    --bootstrap-node=$(curl -H "Accept: text/plain" http://127.0.0.1:8080/api/codex/v1/spr)
146  ```
147  
148  Notice we're using a new data-dir, and we've increased each port number by one. This is needed so that the new node won't try to open ports already in use by the first node.
149  
150  We're now also including the `bootstrap-node` argument. This allows us to link the new node to another one, bootstrapping our own little peer-to-peer network. SPR strings always start with `spr:`.
151  
152  ### 4. Connect The Two
153  
154  Normally the two nodes will automatically connect. If they do not automatically connect or you want to manually connect nodes you can use the peerId to connect nodes.
155  
156  You can get the first node's peer id by running the following command and finding the `"peerId"` in the results:
157  
158  ```shell
159  curl -X GET \
160    -H "Accept: text/plain" \
161    http://127.0.0.1:8081/api/codex/v1/peerid
162  ```
163  
164  Next replace `<PEER ID HERE>` in the following command with the peerId returned from the previous command:
165  
166  ```shell
167  curl -X GET \
168    http://127.0.0.1:8080/api/codex/v1/connect/<PEER ID HERE>?addrs=/ip4/127.0.0.1/tcp/8071
169  ```
170  
171  Alternatively on Mac, Linux, or MSYS2 and a recent Codex binary you can run it in one command like:
172  
173  ```shell
174  curl -X GET \
175    http://127.0.0.1:8080/api/codex/v1/connect/$(curl -X GET -H "Accept: text/plain" http://127.0.0.1:8081/api/codex/v1/peerid)\?addrs=/ip4/127.0.0.1/tcp/8071
176  ```
177  
178  Notice that we are sending the "`peerId`" and the multiaddress of node 2 to the `/connect` endpoint of node 1. This provides node 1 all the information it needs to communicate with node 2. The response to this request should be `Successfully connected to peer`.
179  
180  ### 5. Upload The File
181  
182  We're now ready to upload a file to the network. In this example we'll use node 1 for uploading and node 2 for downloading. But the reverse also works.
183  
184  Next replace `<FILE PATH>` with the path to the file you want to upload in the following command:
185  
186  ```shell
187  curl -X POST \
188    127.0.0.1:8080/api/codex/v1/data \
189    -H "Content-Type: application/octet-stream" \
190    -H "Expect: 100-continue" \
191    -T "<FILE PATH>"
192  ```
193  > [!TIP]
194  > If curl is reluctant to show you the response, add `-o <FILENAME>` to write the result to a file.
195  
196  Depending on the file size this may take a moment. Codex is processing the file by cutting it into blocks and generating erasure-recovery data. When the process is finished, the request will return the content-identifier (CID) of the uploaded file. It should look something like `zdj7WVxH8HHHenKtid8Vkgv5Z5eSUbCxxr8xguTUBMCBD8F2S`.
197  
198  ### 6. Download The File
199  
200  Replace `<CID>` with the identifier returned in the previous step. Replace `<OUTPUT FILE>` with the filename where you want to store the downloaded file:
201  
202  ```bash
203  curl -X GET \
204    127.0.0.1:8081/api/codex/v1/data/<CID>/network \
205    -o <OUTPUT FILE>
206  ```
207  
208  Notice we are connecting to the second node in order to download the file. The CID we provide contains the information needed to locate the file within the network.
209  
210  ### 7. Verify The Results
211  
212  If your file is downloaded and identical to the file you uploaded, then this manual test has passed. Rejoice! If on the other hand that didn't happen or you were unable to complete any of these steps, please leave us a message detailing your troubles.
213  
214  ## Notes
215  
216  When using the Ganache blockchain, there are some deviations from the expected behavior, mainly linked to how blocks are mined, which affects certain functionalities in the Sales module.
217  Therefore, if you are manually testing processes such as payout collection after a request is finished or proof submissions, you need to mine some blocks manually for it to work correctly. You can do this by using the following curl command:
218  
219  ```shell
220  curl -X POST \
221    127.0.0.1:8545 \
222    -H "Content-Type: application/json" \
223    -d '{"jsonrpc":"2.0","method":"evm_mine","params":[],"id":67}'
224  ```
225  
226  ## 알려진 문제점
227  
228  요청이 완료된 후 지불금 수집이나 증명 제출과 같은 프로세스를 수동으로 테스트하는 경우, 제대로 작동하려면 수동으로 블록을 채굴해야 합니다. 다음 curl 명령을 사용하여 이 작업을 수행할 수 있습니다:
229  
230  ```shell
231  curl -X POST \
232    127.0.0.1:8545 \
233    -H "Content-Type: application/json" \
234    -d '{"jsonrpc":"2.0","method":"evm_mine","params":[],"id":67}'
235  ```