@@ -3,19 +3,23 @@ package fuel
3
3
import (
4
4
"context"
5
5
"github.com/ethereum/go-ethereum/common"
6
+ "github.com/sentioxyz/fuel-go/util"
7
+ "github.com/sentioxyz/fuel-go/util/query"
6
8
"github.com/stretchr/testify/assert"
7
9
"testing"
8
10
"time"
9
11
)
10
12
11
- func Test_executeQuery (t * testing.T ) {
12
- cli := NewClient ("https://beta-5.fuel.network/graphql" )
13
+ const testnetEndpoint = "https://beta-5.fuel.network/graphql"
14
+
15
+ func Test_ExecuteQuery (t * testing.T ) {
16
+ cli := NewClient (testnetEndpoint )
13
17
14
18
type result struct {
15
19
Block Block `json:"block"`
16
20
}
17
21
{
18
- query := `
22
+ q := `
19
23
{
20
24
block(height: "9758550") {
21
25
id
@@ -25,7 +29,7 @@ func Test_executeQuery(t *testing.T) {
25
29
}
26
30
}
27
31
}`
28
- r , err := ExecuteQuery [result ](context .Background (), cli , query )
32
+ r , err := ExecuteQuery [result ](context .Background (), cli , q )
29
33
30
34
ti , _ := time .Parse (time .RFC3339 , "2024-04-15T02:44:02Z" )
31
35
assert .NoError (t , err )
@@ -39,7 +43,7 @@ func Test_executeQuery(t *testing.T) {
39
43
}
40
44
41
45
{
42
- query := `
46
+ q := `
43
47
{
44
48
block(height: "9758550") {
45
49
id
@@ -49,8 +53,77 @@ func Test_executeQuery(t *testing.T) {
49
53
}
50
54
}
51
55
}`
52
- _ , err := ExecuteQuery [result ](context .Background (), cli , query )
56
+ _ , err := ExecuteQuery [result ](context .Background (), cli , q )
53
57
54
58
assert .EqualError (t , err , "execute query failed: (line:7,column:7): Unknown field \" tim\" on type \" Header\" . Did you mean \" time\" ?" )
55
59
}
56
60
}
61
+
62
+ func Test_GenObjectQuery (t * testing.T ) {
63
+ assert .Equal (t ,
64
+ "id header { id daHeight transactionsCount messageReceiptCount transactionsRoot messageReceiptRoot height prevRoot time applicationHash } consensus { __typename ... on Genesis { chainConfigHash coinsRoot contractsRoot messagesRoot } ... on PoAConsensus { signature } } " ,
65
+ query .Simple .GenObjectQuery (Block {}, query .IgnoreObjects (Transaction {})),
66
+ )
67
+ assert .Equal (t , `id
68
+ header {
69
+ id
70
+ daHeight
71
+ transactionsCount
72
+ messageReceiptCount
73
+ transactionsRoot
74
+ messageReceiptRoot
75
+ height
76
+ prevRoot
77
+ time
78
+ applicationHash
79
+ }
80
+ consensus {
81
+ __typename
82
+ ... on Genesis {
83
+ chainConfigHash
84
+ coinsRoot
85
+ contractsRoot
86
+ messagesRoot
87
+ }
88
+ ... on PoAConsensus {
89
+ signature
90
+ }
91
+ }
92
+ ` ,
93
+ query .Beauty .GenObjectQuery (Block {}, query .IgnoreObjects (Transaction {})),
94
+ )
95
+
96
+ assert .Equal (t ,
97
+ "id header { id daHeight transactionsCount messageReceiptCount transactionsRoot messageReceiptRoot height prevRoot time applicationHash } consensus { __typename ... on Genesis { chainConfigHash coinsRoot contractsRoot messagesRoot } ... on PoAConsensus { signature } } transactions { id inputAssetIds inputContracts { id bytecode salt } inputContract { utxoId balanceRoot stateRoot txPointer contract { id bytecode salt } } policies { gasPrice witnessLimit maturity maxFee } gasPrice scriptGasLimit maturity mintAmount mintAssetId txPointer isScript isCreate isMint inputs { __typename ... on InputCoin { utxoId owner amount assetId txPointer witnessIndex maturity predicateGasUsed predicate predicateData } ... on InputContract { utxoId balanceRoot stateRoot txPointer contract { id bytecode salt } } ... on InputMessage { sender recipient amount nonce witnessIndex predicateGasUsed data predicate predicateData } } outputs { __typename ... on CoinOutput { to amount assetId } ... on ContractOutput { inputIndex balanceRoot stateRoot } ... on ChangeOutput { to amount assetId } ... on VariableOutput { to amount assetId } ... on ContractCreated { contract { id bytecode salt } stateRoot } } outputContract { inputIndex balanceRoot stateRoot } witnesses receiptsRoot status { __typename ... on SubmittedStatus { time } ... on SqueezedOutStatus { reason } } receipts { contract { id bytecode salt } pc is to { id bytecode salt } toAddress amount assetId gas param1 param2 val ptr digest reason ra rb rc rd len receiptType result gasUsed data sender recipient nonce contractId subId } script scriptData bytecodeWitnessIndex bytecodeLength salt storageSlots rawPayload } " ,
98
+ query .Simple .GenObjectQuery (Block {}, query .IgnoreObjects (SuccessStatus {}, FailureStatus {})),
99
+ )
100
+ }
101
+
102
+ func Test_GenParam (t * testing.T ) {
103
+ assert .Equal (t ,
104
+ `id: "0x5d7f48fc777144b21ea760525936db069329dee2ccce509550c1478c1c0b5b2c" height: "1234" ` ,
105
+ query .Simple .GenParam (QueryBlockParams {
106
+ Id : & BlockId {Hash : common .HexToHash ("0x5d7f48fc777144b21ea760525936db069329dee2ccce509550c1478c1c0b5b2c" )},
107
+ Height : util.GetPointer [U32 ](1234 ),
108
+ }),
109
+ )
110
+ assert .Equal (t ,
111
+ "id: \" 0x5d7f48fc777144b21ea760525936db069329dee2ccce509550c1478c1c0b5b2c\" \n height: \" 1234\" \n " ,
112
+ query .Beauty .GenParam (QueryBlockParams {
113
+ Id : & BlockId {Hash : common .HexToHash ("0x5d7f48fc777144b21ea760525936db069329dee2ccce509550c1478c1c0b5b2c" )},
114
+ Height : util.GetPointer [U32 ](1234 ),
115
+ }),
116
+ )
117
+ assert .Equal (t ,
118
+ "height: \" 1234\" \n " ,
119
+ query .Beauty .GenParam (QueryBlockParams {
120
+ Height : util.GetPointer [U32 ](1234 ),
121
+ }),
122
+ )
123
+ assert .Equal (t ,
124
+ "id: \" 0x5d7f48fc777144b21ea760525936db069329dee2ccce509550c1478c1c0b5b2c\" \n " ,
125
+ query .Beauty .GenParam (QueryBlockParams {
126
+ Id : & BlockId {Hash : common .HexToHash ("0x5d7f48fc777144b21ea760525936db069329dee2ccce509550c1478c1c0b5b2c" )},
127
+ }),
128
+ )
129
+ }
0 commit comments