Skip to content

Commit

Permalink
Merge pull request #585 from okp4/test/block
Browse files Browse the repository at this point in the history
Test/block
  • Loading branch information
ccamel authored Mar 5, 2024
2 parents 9f896a2 + 80b8390 commit 2aade1a
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 124 deletions.
67 changes: 62 additions & 5 deletions docs/predicate/block_height_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ sidebar_position: 5

`block_height/1` is a predicate which unifies the given term with the current block height.

The signature is as follows:
## Signature

```text
block_height(?Height)
block_height(?Height) is det
```

where:
Expand All @@ -21,7 +21,64 @@ where:

## Examples

```text
# Query the current block height.
- block_height(Height).
### Retrieve the block height of the current block

This scenario demonstrates how to retrieve the block height of the current block.

Here's the steps of the scenario:

- **Given** a block with the following header:

| key | value |
| --- | ----- |
| Height | 100 |

- **Given** the query:

``` prolog
block_height(Height).
```

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

``` yaml
has_more: false
variables: ["Height"]
results:
- substitutions:
- variable: Height
expression: "100"
```
### Check that the block height is greater than a certain value
This scenario demonstrates how to check that the block height is greater than 100. This predicate is useful for
governance which requires a certain block height to be reached before a certain action is taken.
Here's the steps of the scenario:
- **Given** a block with the following header:
| key | value |
| --- | ----- |
| Height | 101 |
- **Given** the query:
``` prolog
block_height(Height),
Height > 100.
```

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

``` yaml
has_more: false
variables: ["Height"]
results:
- substitutions:
- variable: Height
expression: "101"
```
68 changes: 63 additions & 5 deletions docs/predicate/block_time_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ sidebar_position: 6

`block_time/1` is a predicate which unifies the given term with the current block time.

The signature is as follows:
## Signature

```text
block_time(?Time)
block_time(?Time) is det
```

where:
Expand All @@ -21,7 +21,65 @@ where:

## Examples

```text
# Query the current block time.
- block_time(Time).
### Retrieve the block time of the current block

This scenario demonstrates how to retrieve the block time of the current block.

Here's the steps of the scenario:

- **Given** a block with the following header:

| key | value |
| --- | ----- |
| Time | 1709550216 |

- **Given** the query:

``` prolog
block_time(Time).
```

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

``` yaml
has_more: false
variables: ["Time"]
results:
- substitutions:
- variable: Time
expression: "1709550216"
```
### Check that the block time is greater than a certain time
This scenario demonstrates how to check that the block time is greater than 1709550216 seconds (Monday 4 March 2024 11:03:36 GMT)
using the `block_time/1` predicate. This predicate is useful for governance which requires a certain block time to be
reached before a certain action is taken.

Here's the steps of the scenario:

- **Given** a block with the following header:

| key | value |
| --- | ----- |
| Time | 1709550217 |

- **Given** the query:

``` prolog
block_time(Time),
Time > 1709550216.
```

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

``` yaml
has_more: false
variables: ["Time"]
results:
- substitutions:
- variable: Time
expression: "1709550217"
```
8 changes: 8 additions & 0 deletions scripts/templates/func.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ Here's the steps of the scenario:
{{ .DocString.Content }}
```
{{- end -}}
{{- if .DataTable -}}
{{- spacer -}}
| key | value |
| --- | ----- |
{{- range .DataTable.Rows }}
| {{ (index .Cells 0).Value }} | {{ (index .Cells 1).Value }} |
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
Expand Down
48 changes: 48 additions & 0 deletions x/logic/keeper/features/block_height_1.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Feature: block_height/1
This feature is to test the block_height/2 predicate.

@great_for_documentation
Scenario: Retrieve the block height of the current block.
This scenario demonstrates how to retrieve the block height of the current block.

Given a block with the following header:
| Height | 100 |

Given the query:
""" prolog
block_height(Height).
"""
When the query is run
Then the answer we get is:
""" yaml
has_more: false
variables: ["Height"]
results:
- substitutions:
- variable: Height
expression: "100"
"""

@great_for_documentation
Scenario: Check that the block height is greater than a certain value.
This scenario demonstrates how to check that the block height is greater than 100. This predicate is useful for
governance which requires a certain block height to be reached before a certain action is taken.

Given a block with the following header:
| Height | 101 |

Given the query:
""" prolog
block_height(Height),
Height > 100.
"""
When the query is run
Then the answer we get is:
""" yaml
has_more: false
variables: ["Height"]
results:
- substitutions:
- variable: Height
expression: "101"
"""
49 changes: 49 additions & 0 deletions x/logic/keeper/features/block_time_1.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Feature: block_time/1
This feature is to test the block_time/2 predicate.

@great_for_documentation
Scenario: Retrieve the block time of the current block.
This scenario demonstrates how to retrieve the block time of the current block.

Given a block with the following header:
| Time | 1709550216 |

Given the query:
""" prolog
block_time(Time).
"""
When the query is run
Then the answer we get is:
""" yaml
has_more: false
variables: ["Time"]
results:
- substitutions:
- variable: Time
expression: "1709550216"
"""

@great_for_documentation
Scenario: Check that the block time is greater than a certain time.
This scenario demonstrates how to check that the block time is greater than 1709550216 seconds (Monday 4 March 2024 11:03:36 GMT)
using the `block_time/1` predicate. This predicate is useful for governance which requires a certain block time to be
reached before a certain action is taken.

Given a block with the following header:
| Time | 1709550217 |

Given the query:
""" prolog
block_time(Time),
Time > 1709550216.
"""
When the query is run
Then the answer we get is:
""" yaml
has_more: false
variables: ["Time"]
results:
- substitutions:
- variable: Time
expression: "1709550217"
"""
Loading

0 comments on commit 2aade1a

Please sign in to comment.