@@ -5,40 +5,40 @@ import 'package:tfchain_client/generated/dev/types/pallet_smart_contract/types/c
5
5
import 'package:tfchain_client/generated/dev/types/pallet_smart_contract/types/contract_lock.dart' ;
6
6
import 'package:tfchain_client/tfchain_client.dart' ;
7
7
8
+ import 'shared_setup.dart' ;
9
+
8
10
void main () {
9
11
group ("Query Contracts Test" , () {
10
12
late QueryClient queryClient;
11
13
final String url =
12
14
Platform .environment['URL' ] ?? 'wss://tfchain.dev.grid.tf/ws' ;
15
+ sharedSetup ();
16
+
13
17
setUp (() async {
14
18
queryClient = QueryClient (url);
15
19
await queryClient.connect ();
16
20
});
17
21
18
- tearDownAll (() async {
19
- await queryClient.disconnect ();
20
- });
21
-
22
22
test ('Test Get Deleted Contract by Id' , () async {
23
23
Contract ? contract =
24
- await queryClient.contracts.get (contractId: BigInt . from ( 97897 ) );
24
+ await queryClient.contracts.get (contractId: deletedContract );
25
25
expect (contract, null );
26
26
});
27
27
28
28
test ('Test Get Contract with wrong id' , () async {
29
29
try {
30
30
Contract ? contract =
31
- await queryClient.contracts.get (contractId: BigInt . from ( - 200 ) );
31
+ await queryClient.contracts.get (contractId: invalidContractId );
32
32
expect (contract, null );
33
33
} catch (error) {
34
34
expect (error, isNotNull);
35
35
}
36
36
});
37
37
38
- test ('Test Get Contract Id by active rent for node' , () async {
38
+ test ('Test Get Contract Id by active rent for invalid node id ' , () async {
39
39
try {
40
40
BigInt ? contractId = await queryClient.contracts
41
- .getContractIdByActiveRentForNode (nodeId: - 200 );
41
+ .getContractIdByActiveRentForNode (nodeId: invalidNodeId );
42
42
expect (contractId, isNotNull);
43
43
} catch (error) {
44
44
expect (error, isNotNull);
@@ -47,15 +47,15 @@ void main() {
47
47
48
48
test ('Test Get Active Contracts by node Id' , () async {
49
49
List <int > contracts =
50
- await queryClient.contracts.getActiveContracts (nodeId: 21 );
50
+ await queryClient.contracts.getActiveContracts (nodeId: nodeId );
51
51
print (contracts);
52
52
expect (contracts, isNotEmpty);
53
53
});
54
54
55
55
test ('Test Get Active Contracts by wrong node Id' , () async {
56
56
try {
57
- List <int > contracts =
58
- await queryClient.contracts. getActiveContracts (nodeId: - 21 );
57
+ List <int > contracts = await queryClient.contracts
58
+ . getActiveContracts (nodeId: invalidNodeId );
59
59
expect (contracts, isNotEmpty);
60
60
} catch (error) {
61
61
expect (error, isNotNull);
@@ -65,7 +65,7 @@ void main() {
65
65
test ('Test Get Contract Id by name' , () async {
66
66
try {
67
67
BigInt ? contractId =
68
- await queryClient.contracts.getContractIdByName (name: "name" );
68
+ await queryClient.contracts.getContractIdByName (name: nameContract );
69
69
expect (contractId, isNotEmpty);
70
70
} catch (error) {
71
71
expect (error, isNotNull);
@@ -75,30 +75,31 @@ void main() {
75
75
test ('Test Get Contract Id by node Id and hash' , () async {
76
76
try {
77
77
BigInt ? contractId = await queryClient.contracts
78
- .getContractIdByNodeIdAndHash (nodeId: 21 , hash: []);
78
+ .getContractIdByNodeIdAndHash (nodeId: nodeId , hash: []);
79
79
expect (contractId, isNotEmpty);
80
80
} catch (error) {
81
81
expect (error, isNotNull);
82
82
}
83
83
});
84
84
85
- test ('Test Get Contract Lock by Id' , () async {
85
+ test ('Test Get Contract Lock by deleted Contract Id' , () async {
86
86
try {
87
87
ContractLock ? contractLock =
88
- await queryClient.contracts.contractLock (id: BigInt .from (97897 ));
89
- print (contractLock);
90
- expect (contractLock, isNotEmpty);
88
+ await queryClient.contracts.contractLock (id: deletedContract);
91
89
} catch (error) {
92
90
expect (error, isNotNull);
93
91
}
94
92
});
95
93
96
94
test ('Test Get a Dedicated Node extra fee' , () async {
97
95
BigInt ? fee =
98
- await queryClient.contracts.getDedicatedNodeExtraFee (nodeId: 140 );
99
- print (fee);
96
+ await queryClient.contracts.getDedicatedNodeExtraFee (nodeId: myNode);
100
97
expect (fee, isNotNull);
101
98
});
99
+
100
+ tearDownAll (() async {
101
+ await queryClient.disconnect ();
102
+ });
102
103
});
103
104
104
105
group ("Test Contracts" , () {
@@ -108,23 +109,13 @@ void main() {
108
109
Platform .environment['URL' ] ?? 'wss://tfchain.dev.grid.tf/ws' ;
109
110
final String type = Platform .environment['KEYPAIR_TYPE' ] ?? 'sr25519' ;
110
111
BigInt ? contractId = null ;
112
+ sharedSetup ();
111
113
112
114
setUp (() async {
113
115
client = Client (url, mnemonic, type);
114
116
await client.connect ();
115
117
});
116
118
117
- tearDownAll (() async {
118
- if (contractId != null ) {
119
- try {
120
- await client.contracts.cancel (contractId: contractId! );
121
- } catch (error) {
122
- print ("Error canceling contract: $error " );
123
- }
124
- }
125
- await client.disconnect ();
126
- });
127
-
128
119
test ('Test Create Node Contract with empty data' , () async {
129
120
try {
130
121
BigInt ? contractId = await client.contracts.createNode (
@@ -136,22 +127,25 @@ void main() {
136
127
137
128
test ('Test Update Node Contract with wrong data' , () async {
138
129
try {
139
- await client.contracts
140
- .updateNode (contractId: 11 , deploymentData: [], deploymentHash: []);
130
+ await client.contracts.updateNode (
131
+ contractId: invalidContractId,
132
+ deploymentData: [],
133
+ deploymentHash: []);
141
134
} catch (error) {
142
135
expect (error, isNotNull);
143
136
}
144
137
});
145
138
146
139
test ('Test Create Name Contract' , () async {
147
- contractId = await client.contracts.createName (name: "xxx" );
140
+ contractId =
141
+ await client.contracts.createName (name: generateRandomString (5 ));
148
142
expect (contractId, isNotNull);
149
143
});
150
144
151
145
test ('Test Create Rent Contract with no solution provider' , () async {
152
146
try {
153
147
BigInt ? contractId = await client.contracts
154
- .createRent (nodeId: 72 , solutionProviderId: BigInt .zero);
148
+ .createRent (nodeId: rentNode , solutionProviderId: BigInt .zero);
155
149
} catch (error) {
156
150
expect (error.toString (), contains ('NoSuchSolutionProvider' ));
157
151
}
@@ -160,10 +154,24 @@ void main() {
160
154
test ('Test set dedicated node extra fee' , () async {
161
155
try {
162
156
await client.contracts
163
- .setDedicatedNodeExtraFee (nodeId: 140 , extraFee: BigInt .two);
157
+ .setDedicatedNodeExtraFee (nodeId: myNode , extraFee: BigInt .two);
164
158
} catch (error) {
165
159
expect (error, isNotNull);
166
160
}
167
161
});
162
+
163
+ tearDown (() async {
164
+ if (contractId != null ) {
165
+ try {
166
+ await client.contracts.cancel (contractId: contractId! );
167
+ } catch (error) {
168
+ print ("Error canceling contract: $error " );
169
+ }
170
+ }
171
+ });
172
+
173
+ tearDownAll (() async {
174
+ await client.disconnect ();
175
+ });
168
176
});
169
177
}
0 commit comments