Skip to content

Commit

Permalink
Merge pull request #602 from okp4/test/stream
Browse files Browse the repository at this point in the history
Test/stream
  • Loading branch information
ccamel authored Mar 18, 2024
2 parents 2a8e823 + 6a90e21 commit 298da3f
Show file tree
Hide file tree
Showing 24 changed files with 1,181 additions and 484 deletions.
186 changes: 186 additions & 0 deletions docs/predicate/consult_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
---
sidebar_position: 8
---
[//]: # (This file is auto-generated. Please do not modify it yourself.)

# consult/1

## Description

`consult/1` is a predicate which read files as Prolog source code.

## Signature

```text
consult(+Files) is det
```

where:

- Files represents the source files to be loaded. It can be an atom or a list of atoms representing the source files.

The Files argument are typically URIs that point to the sources file to be loaded through the Virtual File System \(VFS\). Please refer to the open/4 predicate for more information about the VFS.

## Examples

### Consult a Prolog program

This scenario demonstrates how to consult (load) a Prolog program from a CosmWasm smart contract.

Assuming the existence of a CosmWasm smart contract configured to store a Prolog program, we construct a URI to specifically
identify this smart contract and pinpoint the Prolog program we want to consult via a query message.

Here's the steps of the scenario:

- **Given** the CosmWasm smart contract "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht" and the behavior:

``` yaml
message: |
{
"object_data": {
"id": "4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05"
}
}
response: |
hello("World!").
```
- **Given** the program:
``` prolog
:-
uri_encoded(query_value, '{"object_data":{"id": "4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05"}}', Query),
atom_concat('cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?base64Decode=false&query=', Query, URI),
consult(URI).
```

- **Given** the query:

``` prolog
hello(Who).
```

- **When** the query is run
- **Then** the answer we get is:

``` yaml
has_more: false
variables: ["Who"]
results:
- substitutions:
- variable: Who
expression: "['W',o,r,l,d,!]"
```
### Consult a Prolog program which also consults another Prolog program
This scenario demonstrates the capability of a Prolog program to consult another Prolog program. This is useful for
modularizing Prolog programs and reusing code.
Here's the steps of the scenario:
- **Given** the CosmWasm smart contract "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht" and the behavior:
``` yaml
message: |
{
"object_data": {
"id": "4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05"
}
}
response: |
:- consult('cosmwasm:storage:okp412ssv28mzr02jffvy4x39akrpky9ykfafzyjzmvgsqqdw78yjevpqgmqnmk?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%225d3933430d0a12794fae719e0db87b6ec5f549b2%22%7D%7D&base64Decode=false').
a.
```
- **Given** the CosmWasm smart contract "okp412ssv28mzr02jffvy4x39akrpky9ykfafzyjzmvgsqqdw78yjevpqgmqnmk" and the behavior:
``` yaml
message: |
{
"object_data": {
"id": "5d3933430d0a12794fae719e0db87b6ec5f549b2"
}
}
response: |
b.
```
- **Given** the query:
``` prolog
consult('cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D&base64Decode=false'),
a, b.
```

- **When** the query is run (limited to 2 solutions)
- **Then** the answer we get is:

``` yaml
has_more: false
variables:
results:
- substitutions:
```
### Consult several Prolog programs
This scenario demonstrates the consultation of several Prolog programs from different CosmWasm smart contracts.
Here's the steps of the scenario:
- **Given** the CosmWasm smart contract "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht" and the behavior:
``` yaml
message: |
{
"object_data": {
"id": "4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05"
}
}
response: |
program(a).
```
- **Given** the CosmWasm smart contract "okp412ssv28mzr02jffvy4x39akrpky9ykfafzyjzmvgsqqdw78yjevpqgmqnmk" and the behavior:
``` yaml
message: |
{
"object_data": {
"id": "5d3933430d0a12794fae719e0db87b6ec5f549b2"
}
}
response: |
program(b).
```
- **Given** the program:
``` prolog
:- consult([
'cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D&base64Decode=false',
'cosmwasm:storage:okp412ssv28mzr02jffvy4x39akrpky9ykfafzyjzmvgsqqdw78yjevpqgmqnmk?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%225d3933430d0a12794fae719e0db87b6ec5f549b2%22%7D%7D&base64Decode=false'
]).
```

- **Given** the query:

``` prolog
source_file(File).
```

- **When** the query is run (limited to 2 solutions)
- **Then** the answer we get is:

``` yaml
has_more: false
variables: ["File"]
results:
- substitutions:
- variable: File
expression: "'cosmwasm:storage:okp412ssv28mzr02jffvy4x39akrpky9ykfafzyjzmvgsqqdw78yjevpqgmqnmk?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%225d3933430d0a12794fae719e0db87b6ec5f549b2%22%7D%7D&base64Decode=false'"
- substitutions:
- variable: File
expression: "'cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D&base64Decode=false'"
```
2 changes: 1 addition & 1 deletion docs/predicate/crypto_data_hash_3.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 8
sidebar_position: 9
---
[//]: # (This file is auto-generated. Please do not modify it yourself.)

Expand Down
2 changes: 1 addition & 1 deletion docs/predicate/did_components_2.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 9
sidebar_position: 10
---
[//]: # (This file is auto-generated. Please do not modify it yourself.)

Expand Down
2 changes: 1 addition & 1 deletion docs/predicate/ecdsa_verify_4.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 10
sidebar_position: 11
---
[//]: # (This file is auto-generated. Please do not modify it yourself.)

Expand Down
2 changes: 1 addition & 1 deletion docs/predicate/eddsa_verify_4.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 11
sidebar_position: 12
---
[//]: # (This file is auto-generated. Please do not modify it yourself.)

Expand Down
2 changes: 1 addition & 1 deletion docs/predicate/hex_bytes_2.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 12
sidebar_position: 13
---
[//]: # (This file is auto-generated. Please do not modify it yourself.)

Expand Down
2 changes: 1 addition & 1 deletion docs/predicate/json_prolog_2.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 13
sidebar_position: 14
---
[//]: # (This file is auto-generated. Please do not modify it yourself.)

Expand Down
68 changes: 68 additions & 0 deletions docs/predicate/open_3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
sidebar_position: 16
---
[//]: # (This file is auto-generated. Please do not modify it yourself.)

# open/3

## Description

`open/3` is a predicate which opens a stream to a source or sink. This predicate is a shorthand for open/4 with an empty list of options.

## Signature

```text
open(+SourceSink, +Mode, -Stream)
```

where:

- SourceSink is an atom representing the source or sink of the stream, which is typically a URI.
- Mode is an atom representing the mode of the stream to be opened. It can be one of "read", "write", or "append".
- Stream is the stream to be opened.

open/3 gives True when SourceSink can be opened in Mode.

## Examples

### Open a resource for reading

This scenario showcases the procedure for accessing a resource stored within a CosmWasm smart contract for reading
purposes and obtaining the stream's properties.

See the `open/4` predicate for a more detailed example.

Here's the steps of the scenario:

- **Given** the CosmWasm smart contract "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht" and the behavior:

``` yaml
message: |
{
"object_data": {
"id": "4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05"
}
}
response: |
Hello, World!
```
- **Given** the query:
``` prolog
open(
'cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D&base64Decode=false',
read,
_
).
```

- **When** the query is run
- **Then** the answer we get is:

``` yaml
has_more: false
variables:
results:
- substitutions:
```
Loading

0 comments on commit 298da3f

Please sign in to comment.