forked from FrankSzendzielarz/dotnet-algorand-sdk
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathArc4Tests.cs
More file actions
396 lines (347 loc) · 18.1 KB
/
Copy pathArc4Tests.cs
File metadata and controls
396 lines (347 loc) · 18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
using Algorand.Algod;
using Algorand;
using AVM.ClientGenerator.ABI.ARC32;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Algorand.Algod.Model;
using System.Diagnostics;
using Algorand.KMD;
using System.Linq;
using BiatecClammPool;
using BiatecConfig;
using BiatecIdentity;
using BiatecPoolProvider;
using NUnit.Framework;
namespace test
{
[TestFixture]
public class Arc4Tests
{
[Test]
public async Task GenerateClientAmm()
{
using var client = new HttpClient();
var response = await client.GetAsync("https://raw.githubusercontent.com/scholtz/BiatecCLAMM/refs/heads/main/contracts/artifacts/BiatecClammPool.arc32.json");
Assert.That((int)response.StatusCode, Is.EqualTo(200), "Failed to download file");
var content = await response.Content.ReadAsStringAsync();
Assert.That(content.Trim().StartsWith("{"), Is.True, "File content is not valid JSON");
var ALGOD_API_ADDR = "http://localhost:4001/";
var ALGOD_API_TOKEN = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
var httpClient = HttpClientConfigurator.ConfigureHttpClient(ALGOD_API_ADDR, ALGOD_API_TOKEN);
DefaultApi algodApiInstance = new DefaultApi(httpClient);
var app = await AppDescription.LoadFromByteArray(Encoding.UTF8.GetBytes(content), algodApiInstance);
Assert.That(app.Bare_call_config.No_op, Is.EqualTo(CallConfig.NEVER));
Assert.That(app.Hints.Keys.Count, Is.GreaterThan(1));
Assert.That(app.State.Global, Is.Not.Null);
Assert.That(app.Contract.Methods.Count, Is.GreaterThan(1));
Assert.That(app.Source.Approval.Length, Is.GreaterThan(1));
var appref = app.ToSmartContractReference("BiatecClammPool", "");
Assert.That(appref.Length, Is.GreaterThan(1));
var appProxy = app.ToProxy("BiatecClammPool");
Assert.That(appProxy.Length, Is.GreaterThan(1));
File.WriteAllText("BiatecClammPoolRef.cs", appref);
File.WriteAllText("BiatecClammPoolProxy.cs", appProxy);
GeneratedClientCompiler.CompileAndPublishGeneratedClient("BiatecClammPoolRef.cs", appref);
GeneratedClientCompiler.CompileAndPublishGeneratedClient("BiatecClammPoolProxy.cs", appProxy);
}
[Test]
public async Task GenerateClientPP()
{
using var client = new HttpClient();
var response = await client.GetAsync("https://raw.githubusercontent.com/scholtz/BiatecCLAMM/refs/heads/main/contracts/artifacts/BiatecPoolProvider.arc32.json");
Assert.That((int)response.StatusCode, Is.EqualTo(200), "Failed to download file");
var content = await response.Content.ReadAsStringAsync();
Assert.That(content.Trim().StartsWith("{"), Is.True, "File content is not valid JSON");
var ALGOD_API_ADDR = "http://localhost:4001/";
var ALGOD_API_TOKEN = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
var httpClient = HttpClientConfigurator.ConfigureHttpClient(ALGOD_API_ADDR, ALGOD_API_TOKEN);
DefaultApi algodApiInstance = new DefaultApi(httpClient);
var app = await AppDescription.LoadFromByteArray(Encoding.UTF8.GetBytes(content), algodApiInstance);
Assert.That(app.Bare_call_config.No_op, Is.EqualTo(CallConfig.NEVER));
Assert.That(app.Hints.Keys.Count, Is.GreaterThan(1));
Assert.That(app.State.Global, Is.Not.Null);
Assert.That(app.Contract.Methods.Count, Is.GreaterThan(1));
Assert.That(app.Source.Approval.Length, Is.GreaterThan(1));
var appref = app.ToSmartContractReference("BiatecPoolProvider", "");
Assert.That(appref.Length, Is.GreaterThan(1));
var appProxy = app.ToProxy("BiatecPoolProvider");
Assert.That(appProxy.Length, Is.GreaterThan(1));
File.WriteAllText("BiatecPoolProviderRef.cs", appref);
File.WriteAllText("BiatecPoolProviderProxy.cs", appProxy);
GeneratedClientCompiler.CompileAndPublishGeneratedClient("BiatecPoolProviderRef.cs", appref);
GeneratedClientCompiler.CompileAndPublishGeneratedClient("BiatecPoolProviderProxy.cs", appProxy);
}
[Test]
public async Task GenerateClientConf()
{
using var client = new HttpClient();
var response = await client.GetAsync("https://raw.githubusercontent.com/scholtz/BiatecCLAMM/refs/heads/main/contracts/artifacts/BiatecConfigProvider.arc32.json");
Assert.That((int)response.StatusCode, Is.EqualTo(200), "Failed to download file");
var content = await response.Content.ReadAsStringAsync();
Assert.That(content.Trim().StartsWith("{"), Is.True, "File content is not valid JSON");
var ALGOD_API_ADDR = "http://localhost:4001/";
var ALGOD_API_TOKEN = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
var httpClient = HttpClientConfigurator.ConfigureHttpClient(ALGOD_API_ADDR, ALGOD_API_TOKEN);
DefaultApi algodApiInstance = new DefaultApi(httpClient);
var app = await AppDescription.LoadFromByteArray(Encoding.UTF8.GetBytes(content), algodApiInstance);
Assert.That(app.Bare_call_config.No_op, Is.EqualTo(CallConfig.NEVER));
Assert.That(app.Hints.Keys.Count, Is.GreaterThan(1));
Assert.That(app.State.Global, Is.Not.Null);
Assert.That(app.Contract.Methods.Count, Is.GreaterThan(1));
Assert.That(app.Source.Approval.Length, Is.GreaterThan(1));
var appref = app.ToSmartContractReference("BiatecConfig", "");
Assert.That(appref.Length, Is.GreaterThan(1));
var appProxy = app.ToProxy("BiatecConfig");
Assert.That(appProxy.Length, Is.GreaterThan(1));
File.WriteAllText("BiatecConfigProviderRef.cs", appref);
File.WriteAllText("BiatecConfigProviderProxy.cs", appProxy);
GeneratedClientCompiler.CompileAndPublishGeneratedClient("BiatecConfigProviderRef.cs", appref);
GeneratedClientCompiler.CompileAndPublishGeneratedClient("BiatecConfigProviderProxy.cs", appProxy);
}
[Test]
public async Task GenerateClientBI()
{
using var client = new HttpClient();
var response = await client.GetAsync("https://raw.githubusercontent.com/scholtz/BiatecCLAMM/refs/heads/main/contracts/artifacts/BiatecIdentityProvider.arc32.json");
Assert.That((int)response.StatusCode, Is.EqualTo(200), "Failed to download file");
var content = await response.Content.ReadAsStringAsync();
Assert.That(content.Trim().StartsWith("{"), Is.True, "File content is not valid JSON");
var ALGOD_API_ADDR = "http://localhost:4001/";
var ALGOD_API_TOKEN = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
var httpClient = HttpClientConfigurator.ConfigureHttpClient(ALGOD_API_ADDR, ALGOD_API_TOKEN);
DefaultApi algodApiInstance = new DefaultApi(httpClient);
var app = await AppDescription.LoadFromByteArray(Encoding.UTF8.GetBytes(content), algodApiInstance);
Assert.That(app.Bare_call_config.No_op, Is.EqualTo(CallConfig.NEVER));
Assert.That(app.Hints.Keys.Count, Is.GreaterThan(1));
Assert.That(app.State.Global, Is.Not.Null);
Assert.That(app.Contract.Methods.Count, Is.GreaterThan(1));
Assert.That(app.Source.Approval.Length, Is.GreaterThan(1));
var appref = app.ToSmartContractReference("BiatecIdentity", "");
Assert.That(appref.Length, Is.GreaterThan(1));
var appProxy = app.ToProxy("BiatecIdentity");
Assert.That(appProxy.Length, Is.GreaterThan(1));
File.WriteAllText("BiatecIdentityProviderRef.cs", appref);
File.WriteAllText("BiatecIdentityProviderProxy.cs", appProxy);
GeneratedClientCompiler.CompileAndPublishGeneratedClient("BiatecIdentityProviderRef.cs", appref);
GeneratedClientCompiler.CompileAndPublishGeneratedClient("BiatecIdentityProviderProxy.cs", appProxy);
}
private async Task<Account> GetAccount()
{
//A standard sandbox connection
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-KMD-API-Token", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
var kmdApi = new Api(client);
kmdApi.BaseUrl = @"http://localhost:4002";
var handle = await getWalletHandleToken(kmdApi);
var accs = await kmdApi.ListKeysInWalletAsync(new ListKeysRequest() { Wallet_handle_token = handle });
var a = accs.Addresses.First();
var resp = await kmdApi.ExportKeyAsync(new ExportKeyRequest() { Address = a, Wallet_handle_token = handle, Wallet_password = "" });
return new Account(resp.Private_key);
}
private static async Task<string> getWalletHandleToken(Api kmdApi)
{
var wallets = await kmdApi.ListWalletsAsync(null);
var wallet = wallets.Wallets.FirstOrDefault();
var handle = await kmdApi.InitWalletHandleTokenAsync(new InitWalletHandleTokenRequest() { Wallet_id = wallet.Id, Wallet_password = "" });
return handle.Wallet_handle_token;
}
[Test]
public async Task DeployProxiedApp()
{
var ALGOD_API_ADDR = "http://localhost:4001/";
var ALGOD_API_TOKEN = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
var httpClient = HttpClientConfigurator.ConfigureHttpClient(ALGOD_API_ADDR, ALGOD_API_TOKEN);
DefaultApi algodApiInstance = new DefaultApi(httpClient);
Account acct1 = await GetAccount();
var contract = new BiatecClammPoolProxy(algodApiInstance, 0);
try
{
await contract.createApplication(acct1, 1000, "", _tx_callType: AVM.ClientGenerator.Core.OnCompleteType.CreateApplication);
}
catch (Algorand.ApiException<Algorand.Algod.Model.ErrorResponse> e)
{
Trace.TraceError(e.Message);
throw;
}
catch (Algorand.ApiException e)
{
Trace.TraceError(e.Message);
throw;
}
catch (AVM.ClientGenerator.ProxyException e)
{
var eApi = e.InnerException as Algorand.ApiException<Algorand.Algod.Model.ErrorResponse>;
if (eApi != null)
{
Trace.TraceError(eApi.Result.Message.ToString());
}
Trace.TraceError(e.Message);
throw;
}
}
[Test]
public async Task DeployAppMakeAppCall()
{
var ALGOD_API_ADDR = "http://localhost:4001/";
var ALGOD_API_TOKEN = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
var httpClient = HttpClientConfigurator.ConfigureHttpClient(ALGOD_API_ADDR, ALGOD_API_TOKEN);
DefaultApi algodApiInstance = new DefaultApi(httpClient);
var trans = await algodApiInstance.TransactionParamsAsync();
Account acct1 = await GetAccount();
var contract = new BiatecConfigProviderProxy(algodApiInstance, 0);
try
{
await contract.createApplication(acct1, 1000, "", _tx_callType: AVM.ClientGenerator.Core.OnCompleteType.CreateApplication);
await contract.bootstrap(
_tx_sender: acct1,
_tx_fee: 1000,
biatecFee: new AVM.ClientGenerator.ABI.ARC4.Types.UInt256(1),
appBiatecIdentityProvider: 101,
appBiatecPoolProvider: 102,
_tx_note: "",
_tx_boxes: new List<BoxRef>()
);
}
catch (Algorand.ApiException<Algorand.Algod.Model.ErrorResponse> e)
{
Trace.TraceError(e.Message);
throw;
}
catch (Algorand.ApiException e)
{
Trace.TraceError(e.Message);
throw;
}
catch (AVM.ClientGenerator.ProxyException e)
{
var eApi = e.InnerException as Algorand.ApiException<Algorand.Algod.Model.ErrorResponse>;
if (eApi != null)
{
Trace.TraceError(eApi.Result.Message.ToString());
}
Trace.TraceError(e.Message);
throw;
}
}
[Test]
public async Task DeployBI()
{
var ALGOD_API_ADDR = "http://localhost:4001/";
var ALGOD_API_TOKEN = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
var httpClient = HttpClientConfigurator.ConfigureHttpClient(ALGOD_API_ADDR, ALGOD_API_TOKEN);
DefaultApi algodApiInstance = new DefaultApi(httpClient);
var trans = await algodApiInstance.TransactionParamsAsync();
Account acct1 = await GetAccount();
var contractConf = new BiatecConfigProviderProxy(algodApiInstance, 0);
var contractBI = new BiatecIdentityProviderProxy(algodApiInstance, 0);
var contractPP = new BiatecPoolProviderProxy(algodApiInstance, 0);
try
{
await contractConf.createApplication(acct1, 1000, "", _tx_callType: AVM.ClientGenerator.Core.OnCompleteType.CreateApplication);
await contractBI.createApplication(acct1, 1000, "", _tx_callType: AVM.ClientGenerator.Core.OnCompleteType.CreateApplication);
await contractPP.createApplication(acct1, 1000, "", _tx_callType: AVM.ClientGenerator.Core.OnCompleteType.CreateApplication);
await contractConf.bootstrap(
_tx_sender: acct1,
_tx_fee: 1000,
biatecFee: new AVM.ClientGenerator.ABI.ARC4.Types.UInt256(1),
appBiatecIdentityProvider: contractBI.appId,
appBiatecPoolProvider: contractPP.appId,
_tx_note: "",
_tx_boxes: new List<BoxRef>()
);
await contractPP.bootstrap(
_tx_sender: acct1,
_tx_fee: 1000,
appBiatecConfigProvider: contractConf.appId,
_tx_note: "",
_tx_apps: new List<ulong>() { contractConf.appId }
);
await contractBI.bootstrap(
governor: acct1.Address,
verificationSetter: acct1.Address,
engagementSetter: acct1.Address,
_tx_sender: acct1,
_tx_fee: 1000,
appBiatecConfigProvider: contractConf.appId,
_tx_note: "",
_tx_apps: new List<ulong>() { contractConf.appId }
);
}
catch (Algorand.ApiException<Algorand.Algod.Model.ErrorResponse> e)
{
Trace.TraceError(e.Message);
throw;
}
catch (Algorand.ApiException e)
{
Trace.TraceError(e.Message);
throw;
}
catch (AVM.ClientGenerator.ProxyException e)
{
var eApi = e.InnerException as Algorand.ApiException<Algorand.Algod.Model.ErrorResponse>;
if (eApi != null)
{
Trace.TraceError(eApi.Result.Message.ToString());
}
Trace.TraceError(e.Message);
throw;
}
}
//[Test]
//public async Task DeployAppMakeAppCall()
//{
// var ALGOD_API_ADDR = "http://localhost:4001/";
// var ALGOD_API_TOKEN = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
// var httpClient = HttpClientConfigurator.ConfigureHttpClient(ALGOD_API_ADDR, ALGOD_API_TOKEN);
// DefaultApi algodApiInstance = new DefaultApi(httpClient);
// var trans = await algodApiInstance.TransactionParamsAsync();
// Account acct1 = await GetAccount();
// var contract = new BiatecClammPoolProxy(algodApiInstance, 0);
// try
// {
// await contract.createApplication(acct1, 1000, "", new List<BoxRef>(), AVM.ClientGenerator.Core.OnCompleteType.CreateApplication);
// await contract.bootstrap(
// acct1,
// 2000,
// PaymentTransaction.GetPaymentTransactionFromNetworkTransactionParameters(acct1.Address, contract.AppAddress, 400000, "", trans),
// assetA: 100,
// assetB: 101,
// appBiatecConfigProvider: 110,
// appBiatecPoolProvider: 111,
// fee: 2000,
// priceMin: 0,
// priceMax: 1000,
// currentPrice: 1000,
// verificationClass: 2,
// note: "",
// boxes: new List<BoxRef>()
// );
// }
// catch (Algorand.ApiException<Algorand.Algod.Model.ErrorResponse> e)
// {
// Trace.TraceError(e.Message);
// throw;
// }
// catch (Algorand.ApiException e)
// {
// Trace.TraceError(e.Message);
// throw;
// }
// catch (AVM.ClientGenerator.ProxyException e)
// {
// var eApi = e.InnerException as Algorand.ApiException<Algorand.Algod.Model.ErrorResponse>;
// if (eApi != null)
// {
// Trace.TraceError(eApi.Result.Message.ToString());
// }
// Trace.TraceError(e.Message);
// throw;
// }
//}
/**/
}
}