-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathEsdtTokenIntegrationTests.cs
157 lines (129 loc) · 7.63 KB
/
EsdtTokenIntegrationTests.cs
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
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Numerics;
using System.Threading.Tasks;
using Erdcsharp.Configuration;
using Erdcsharp.Domain;
using Erdcsharp.Manager;
using Erdcsharp.Provider;
using Erdcsharp.UnitTests.FakeData;
using NUnit.Framework;
namespace Erdcsharp.IntegrationTests
{
[TestFixture(Category = "LongRunning", Description = "EsdtTokenManager usage")]
public class EsdtTokenIntegrationTests
{
private IElrondProvider _provider;
private IEsdtTokenManager _tokenManager;
private TestWalletFactory _testWalletFactory;
[SetUp]
public void Setup()
{
_provider = new ElrondProvider(new HttpClient(), new ElrondNetworkConfiguration(Network.TestNet));
_tokenManager = new EsdtTokenManager(_provider);
_testWalletFactory = new TestWalletFactory();
}
[Test(Description = "Issue an ESDT FungibleESDT Token with a 1,000,000,000 initial supply")]
public async Task Create_Esdt_Fungible_Token_For_Alice()
{
var wallet = _testWalletFactory.Alice;
var account = wallet.GetAccount();
await account.Sync(_provider);
var token = Token.ESDT("MYTOKEN", "MTCK", 18);
var initialSupply = TokenAmount.ESDT("1000000", token);
var tokenIdentifier = await _tokenManager.IssueFungibleToken(
wallet,
token,
initialSupply.Value);
// ex : MTCK-0accc7
Assert.That(tokenIdentifier.StartsWith(token.Ticker), "Token identifier should start with the Ticker");
Assert.That(tokenIdentifier.Length, Is.EqualTo(token.Ticker.Length + 7),
"Token identifier should be ticker-[6 char]");
await Transfer_One_ESDT_Token_From_Alice_To_Bob(tokenIdentifier);
}
[Test(Description = "Issue an ESDT NFT Token and create 1 token")]
public async Task Create_Esdt_NFT_Token_For_Alice()
{
var wallet = _testWalletFactory.Alice;
var account = wallet.GetAccount();
await account.Sync(_provider);
var token = Token.ESDT_NFT("MYNFTTOKEN", "MYNFT");
var tokenIdentifier = await _tokenManager.IssueNonFungibleToken(
wallet,
token.Name,
token.Ticker);
Assert.That(tokenIdentifier.StartsWith(token.Ticker), "Token identifier should start with the Ticker");
Assert.That(tokenIdentifier.Length, Is.EqualTo(token.Ticker.Length + 7),
"Token identifier should be ticker-[6 char]");
// Set the 'ESDTRoleNFTCreate' special role to alice
await _tokenManager.SetSpecialRole(wallet, tokenIdentifier,
Constants.EsdtNftSpecialRoles.EsdtRoleNftCreate);
// Create the 'My foo NFT' NFT token
var tokenId = await _tokenManager.CreateNftToken(
wallet,
tokenIdentifier,
BigInteger.One,
"My foo NFT",
450,
new Dictionary<string, string>(),
new[] {new Uri("https://www.foo.bar")});
Assert.That(tokenId, Is.EqualTo(1));
}
[Test(Description = "Issue an ESDT SFT Token and create 5000 tokens")]
public async Task Create_Esdt_SFT_Token_For_Alice()
{
var wallet = _testWalletFactory.Alice;
var account = wallet.GetAccount();
await account.Sync(_provider);
var token = Token.ESDT_NFT("MYSFTTOKEN", "MYSFT");
var tokenIdentifier = await _tokenManager.IssueSemiFungibleToken(
wallet,
token.Name,
token.Ticker);
Assert.That(tokenIdentifier.StartsWith(token.Ticker), "Token identifier should start with the Ticker");
Assert.That(tokenIdentifier.Length, Is.EqualTo(token.Ticker.Length + 7),
"Token identifier should be ticker-[6 char]");
// Set the 'ESDTRoleNFTCreate' special role to alice
await _tokenManager.SetSpecialRole(wallet, tokenIdentifier,
Constants.EsdtSftSpecialRoles.EsdtRoleNftCreate,
Constants.EsdtSftSpecialRoles.EsdtRoleNftAddQuantity);
// Create the 'My foo NFT' NFT token
var tokenId = await _tokenManager.CreateNftToken(
wallet,
tokenIdentifier,
5000,
"My foo SFT",
450,
new Dictionary<string, string>()
{
{"artist", "my artist"},
{"foo", "bar"}
},
new[] {new Uri("https://www.foo.bar")});
Assert.That(tokenId, Is.EqualTo(1));
}
[Test(Description = "Get a collection of ESDT Tokens for alice")]
public async Task Query_Esdt_Tokens_For_Address()
{
var alice = _testWalletFactory.Alice.GetAccount().Address;
var tokens = await _tokenManager.GetEsdtTokens(alice);
Assert.That(tokens, Is.Not.Null);
Assert.Pass();
}
private async Task Transfer_One_ESDT_Token_From_Alice_To_Bob(string tokenIdentifier)
{
await Task.Delay(5000);
var alice = _testWalletFactory.Alice;
var aliceAccount = alice.GetAccount();
var bob = _testWalletFactory.Bob.GetAccount().Address;
var tokenInBobAccount = await _tokenManager.GetEsdtFungibleToken(bob, tokenIdentifier);
Assert.That(tokenInBobAccount.Balance.IsZero, Is.True, "Bob should not have any token at this time");
var tokenInAliceAccount = await _tokenManager.GetEsdtFungibleToken(aliceAccount.Address, tokenIdentifier);
Assert.That(tokenInAliceAccount.Balance > 1, Is.True, "Alice should have at least 1 token");
await _tokenManager.TransferEsdtToken(alice, tokenInAliceAccount, bob, BigInteger.One);
tokenInBobAccount = await _tokenManager.GetEsdtFungibleToken(bob, tokenIdentifier);
Assert.That(tokenInBobAccount.Balance.IsOne, Is.True, "Bob should have only one token");
}
}
}