This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathtest_signature_mint_20.py
105 lines (87 loc) · 2.99 KB
/
test_signature_mint_20.py
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
from time import time
from thirdweb.constants.currency import NATIVE_TOKEN_ADDRESS, ZERO_ADDRESS
from thirdweb.constants.role import Role
from thirdweb.contracts.token import Token
from thirdweb.types.contracts.signature import PayloadToSign20, PayloadToSign20
from thirdweb.types.currency import TokenAmount
from thirdweb.core.sdk import ThirdwebSDK
from brownie import accounts
import pytest
from thirdweb.types.settings.metadata import (
TokenContractMetadata,
)
@pytest.mark.usefixtures("sdk", "primary_account")
@pytest.fixture(scope="function")
def token(sdk: ThirdwebSDK, primary_account) -> Token:
sdk.update_signer(primary_account)
token = sdk.get_token(
sdk.deployer.deploy_token(
TokenContractMetadata(
name="Token Sigmint",
symbol="TSIG",
primary_sale_recipient=sdk.get_signer().address, # type: ignore
)
)
)
custom_token = sdk.get_token(
sdk.deployer.deploy_token(
TokenContractMetadata(
name="Test",
symbol="TEST",
primary_sale_recipient=sdk.get_signer().address, # type: ignore
)
)
)
custom_token.mint_batch_to(
[
TokenAmount(to_address=accounts[0].address, amount=1000),
TokenAmount(to_address=accounts[1].address, amount=1000),
TokenAmount(to_address=sdk.get_signer().address, amount=1000), # type: ignore
]
)
return custom_token
@pytest.fixture
def metadata() -> PayloadToSign20:
return PayloadToSign20(
to=accounts[0].address,
price=0,
currency_address=NATIVE_TOKEN_ADDRESS,
primary_sale_recipient=ZERO_ADDRESS,
quantity=1,
mint_end_time=int(time() + 60 * 60 * 24),
mint_start_time=int(time()) - 1800,
uid=None,
)
def test_generate_valid_signature(token: Token, metadata: PayloadToSign20):
good_payload = token.signature.generate(metadata)
valid = token.signature.verify(good_payload)
assert valid
token.signature.mint(good_payload)
@pytest.mark.usefixtures("sdk", "primary_account", "secondary_account")
def test_claiming(
sdk: ThirdwebSDK,
token: Token,
primary_account,
secondary_account,
):
payloads = []
free_mint = PayloadToSign20(
to=accounts[0].address,
price=0,
currency_address=NATIVE_TOKEN_ADDRESS,
quantity=1,
primary_sale_recipient=ZERO_ADDRESS,
mint_end_time=int(time() + 60 * 60 * 24),
mint_start_time=int(time()) - 1800,
uid=None,
)
for i in range(0, 10):
payloads.append(free_mint)
balance = token.balance_of(accounts[0].address)
assert balance.display_value == 1000
batch = [token.signature.generate(p) for p in payloads]
sdk.update_signer(secondary_account)
tx = token.signature.mint_batch(batch)
sdk.update_signer(primary_account)
balance = token.balance_of(accounts[0].address)
assert balance.display_value == 1010