Skip to content

Commit

Permalink
[GraphQL/MovePackage] Query for latest version
Browse files Browse the repository at this point in the history
## Description

Add a new kind of package point look-up to get the latest version of
the package at a given ID (or from another `MovePackage`). For system
packages, this is analogous to getting the latest version of the
object at that ID, but the versions of other packages all exist at
different IDs.

## Test plan

New transactional tests:

```
sui$ cargo nextest run -p sui-graphql-e2e-tests \
  --features pg_integration                     \
  -- packages/versioning
```
  • Loading branch information
amnn committed May 14, 2024
1 parent 0af22bd commit a84ac48
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 12 deletions.
142 changes: 131 additions & 11 deletions crates/sui-graphql-e2e-tests/tests/packages/versioning.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
processed 9 tasks
processed 14 tasks

init:
A: object(0,0)
Expand All @@ -8,20 +8,89 @@ created: object(1,0), object(1,1)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 5076800, storage_rebate: 0, non_refundable_storage_fee: 0

task 2 'upgrade'. lines 11-15:
created: object(2,0)
task 2 'create-checkpoint'. lines 11-11:
Checkpoint created: 1

task 3 'run-graphql'. lines 13-21:
Response: {
"data": {
"latestPackage": {
"version": 1,
"module": {
"functions": {
"nodes": [
{
"name": "f"
}
]
}
}
}
}
}

task 4 'upgrade'. lines 23-27:
created: object(4,0)
mutated: object(0,0), object(1,1)
gas summary: computation_cost: 1000000, storage_cost: 5251600, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 3 'upgrade'. lines 17-22:
created: object(3,0)
task 5 'create-checkpoint'. lines 29-29:
Checkpoint created: 2

task 6 'run-graphql'. lines 31-39:
Response: {
"data": {
"latestPackage": {
"version": 2,
"module": {
"functions": {
"nodes": [
{
"name": "f"
},
{
"name": "g"
}
]
}
}
}
}
}

task 7 'upgrade'. lines 41-46:
created: object(7,0)
mutated: object(0,0), object(1,1)
gas summary: computation_cost: 1000000, storage_cost: 5426400, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 4 'create-checkpoint'. lines 24-24:
Checkpoint created: 1
task 8 'create-checkpoint'. lines 48-48:
Checkpoint created: 3

task 9 'run-graphql'. lines 50-58:
Response: {
"data": {
"latestPackage": {
"version": 3,
"module": {
"functions": {
"nodes": [
{
"name": "f"
},
{
"name": "g"
},
{
"name": "h"
}
]
}
}
}
}
}

task 5 'run-graphql'. lines 26-45:
task 10 'run-graphql'. lines 60-97:
Response: {
"data": {
"v1": {
Expand All @@ -33,6 +102,23 @@ Response: {
}
]
}
},
"latest": {
"module": {
"functions": {
"nodes": [
{
"name": "f"
},
{
"name": "g"
},
{
"name": "h"
}
]
}
}
}
},
"v2": {
Expand All @@ -47,6 +133,23 @@ Response: {
}
]
}
},
"latest": {
"module": {
"functions": {
"nodes": [
{
"name": "f"
},
{
"name": "g"
},
{
"name": "h"
}
]
}
}
}
},
"v3": {
Expand All @@ -64,12 +167,29 @@ Response: {
}
]
}
},
"latest": {
"module": {
"functions": {
"nodes": [
{
"name": "f"
},
{
"name": "g"
},
{
"name": "h"
}
]
}
}
}
}
}
}

task 6 'run-graphql'. lines 47-84:
task 11 'run-graphql'. lines 99-136:
Response: {
"data": {
"v1_from_p1": {
Expand Down Expand Up @@ -159,7 +279,7 @@ Response: {
}
}

task 7 'run-graphql'. lines 86-141:
task 12 'run-graphql'. lines 138-193:
Response: {
"data": {
"v1": {
Expand Down Expand Up @@ -297,7 +417,7 @@ Response: {
}
}

task 8 'run-graphql'. lines 143-171:
task 13 'run-graphql'. lines 195-223:
Response: {
"data": {
"v0": null,
Expand Down
52 changes: 52 additions & 0 deletions crates/sui-graphql-e2e-tests/tests/packages/versioning.move
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,36 @@ module P0::m {
public fun f(): u64 { 42 }
}

//# create-checkpoint

//# run-graphql
{
latestPackage(address: "@{P0}") {
version
module(name: "m") {
functions { nodes { name } }
}
}
}

//# upgrade --package P0 --upgrade-capability 1,1 --sender A
module P1::m {
public fun f(): u64 { 42 }
public fun g(): u64 { 43 }
}

//# create-checkpoint

//# run-graphql
{
latestPackage(address: "@{P0}") {
version
module(name: "m") {
functions { nodes { name } }
}
}
}

//# upgrade --package P1 --upgrade-capability 1,1 --sender A
module P2::m {
public fun f(): u64 { 42 }
Expand All @@ -23,24 +47,52 @@ module P2::m {

//# create-checkpoint

//# run-graphql
{
latestPackage(address: "@{P0}") {
version
module(name: "m") {
functions { nodes { name } }
}
}
}

//# run-graphql
{ # Test fetching by ID
v1: package(address: "@{P0}") {
module(name: "m") {
functions { nodes { name } }
}

latest {
module(name: "m") {
functions { nodes { name } }
}
}
}

v2: package(address: "@{P1}") {
module(name: "m") {
functions { nodes { name } }
}

latest {
module(name: "m") {
functions { nodes { name } }
}
}
}

v3: package(address: "@{P2}") {
module(name: "m") {
functions { nodes { name } }
}

latest {
module(name: "m") {
functions { nodes { name } }
}
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions crates/sui-graphql-rpc/schema/current_progress_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,11 @@ type MovePackage implements IObject & IOwner {
"""
atVersion(version: Int!): MovePackage
"""
Fetch the latest version of this package (the package with the highest `version` that shares
this packages's original ID)
"""
latest: MovePackage!
"""
A representation of the module called `name` in this package, including the
structs and functions it defines.
"""
Expand Down Expand Up @@ -2874,6 +2879,13 @@ type Query {
"""
package(address: SuiAddress!, version: Int): MovePackage
"""
The latest version of the package at `address`.
This corresponds to the package with the highest `version` that shares its original ID with
the package at `address`.
"""
latestPackage(address: SuiAddress!): MovePackage
"""
Look-up an Account by its SuiAddress.
"""
address(address: SuiAddress!): Address
Expand Down
Loading

0 comments on commit a84ac48

Please sign in to comment.