# Test

### Set LiquidStorage Configuration

The `setstoragecfg` table allows setting limits to the LiquidStorage service for users. This is an optional step.

```cpp
TABLE storagecfg {
  // all measurements in bytes
  uint64_t max_file_size_in_bytes = UINT64_MAX; // max file size in bytes that can be uploaded at a time, default 10mb
  uint64_t global_upload_limit_per_day = UINT64_MAX; // max upload limit in bytes per day for EOS account, default 1 GB
  uint64_t vaccount_upload_limit_per_day = UINT64_MAX; // max upload limit in bytes per day for LiquidAccounts, default 10 MB
};
```

Here we will set the maximum file size to 1MB and the global upload limits to 10MB each. You can update the `YOUR_ACCOUNT_HERE` to your consumer account.

```bash
cleos -u https://kylin.eosn.io push transaction '{"delay_sec":0,"max_cpu_usage_ms":0,"actions":[{"account":"YOUR_ACCOUNT_HERE","name":"setstoragecfg","data":{"max_file_size_in_bytes":1000000,"global_upload_limit_per_day":100000000,"vaccount_upload_limit_per_day":100000000},"authorization":[{"actor":"YOUR_ACCOUNT_HERE","permission":"active"}]}]}'
```

### Test

This test will use a regular EOS account instead of a LiquidAccount, to use a LiquidAccount, visit the [LiquidAccount](https://docs.liquidapps.io/liquidapps-documentation/dapp-network-services/dapp-network-services/liquidaccounts) section for how to send a transaction.

First install the [dapp-client](https://docs.liquidapps.io/liquidapps-documentation/introduction/dapp-network-resources/liquidapps-dapp-client)

```bash
npm install -g @liquidapps/dapp-client
```

Create the following file:

```bash
touch test.js
# add contents below
vim test.js
# run file
node test.js
```

```javascript
const { createClient } = require('@liquidapps/dapp-client');
const fetch = require('isomorphic-fetch');
const endpoint = "https://kylin-dsp-2.liquidapps.io";
const getClient = () => createClient( { network:"kylin", httpEndpoint: endpoint, fetch });

(async () => {
    const service = await (await getClient()).service('storage', "YOUR_ACCOUNT_HERE");
    const data = Buffer.from("a great success", "utf8");
    const key = "YOUR_ACTIVE_PRIVATE_KEY_HERE";
    const permission = "active";
    const options = {
      // if true, DAG leaves will contain raw file data and not be wrapped in a protobuf
      rawLeaves: true
    };
    const response = await service.upload_public_file(
        data,
        key,
        permission,
        null,
        options
    );
    console.log(`response uri: ${response.uri}`);
})().catch((e) => { console.log(e); });
```

```bash
# node test.js 
response uri: ipfs://IPFS_URI_HERE
```

This will return the IPFS URI where the content can be fetched.

Add the URI to the end of the IPFS gateway: `https://ipfs.io/ipfs/IPFS_URI_HERE`, and you will see “a great success”.

To fetch data, the following example can be used:

```javascript
const fetch = require("node-fetch");

(async () => {
    let res = await fetch('https://kylin-dsp-2.liquidapps.io/v1/dsp/liquidstorag/get_uri', {
      method: 'POST',
      mode: 'cors',
      body: JSON.stringify({ uri: "ipfs://zb2rhX28fttoDTUhpmHBgQa2PzjL1N3XUDaL9rZvx8dLZseji" })
    });
    res = await res.json();
    res = Buffer.from(res.data, 'base64').toString(),
    console.log(`result: ${res}`);
})().catch((e) => { console.log(e); });
// result: a great success
```

To see additional examples of the other `dapp-client` services, see the examples folder [here](https://github.com/liquidapps-io/zeus-sdk/tree/master/boxes/groups/services/storage-dapp-service/client/examples).
