genlayer 0.18.4 → 0.18.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/templates/default/README.md +5 -5
- package/templates/default/contracts/football_bets.py +9 -9
- package/templates/default/deploy/deployScript.ts +6 -1
- package/templates/default/requirements.txt +4 -5
- package/templates/default/test/football_bets_get_contract_schema_for_code.py +7 -7
- package/templates/default/test/test_football_bet.py +140 -0
- package/templates/default/test/test_football_bet_success_draw.py +0 -108
- package/templates/default/test/test_football_bet_success_win.py +0 -106
- package/templates/default/test/test_football_bet_unsuccess.py +0 -107
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -17723,7 +17723,7 @@ var require_semver2 = __commonJS({
|
|
|
17723
17723
|
import { program } from "commander";
|
|
17724
17724
|
|
|
17725
17725
|
// package.json
|
|
17726
|
-
var version = "0.18.
|
|
17726
|
+
var version = "0.18.5";
|
|
17727
17727
|
var package_default = {
|
|
17728
17728
|
name: "genlayer",
|
|
17729
17729
|
version,
|
package/package.json
CHANGED
|
@@ -45,12 +45,12 @@ This project includes the boilerplate code for a GenLayer use case implementatio
|
|
|
45
45
|
The terminal should display a link to access your frontend app (usually at http://localhost:5173/).
|
|
46
46
|
For more information on the code see [GenLayerJS](https://github.com/yeagerai/genlayer-js).
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
### 5. Test contracts
|
|
49
49
|
1. Install the Python packages listed in the `requirements.txt` file in a virtual environment.
|
|
50
50
|
2. Make sure your GenLayer Studio is running. Then execute the following command in your terminal:
|
|
51
51
|
```shell
|
|
52
|
-
|
|
53
|
-
```
|
|
52
|
+
gltest
|
|
53
|
+
```
|
|
54
54
|
|
|
55
55
|
## ⚽ How the Football Bets Contract Works
|
|
56
56
|
|
|
@@ -73,7 +73,7 @@ The Football Bets contract allows users to create bets for football matches, res
|
|
|
73
73
|
- Points are awarded for correct bets.
|
|
74
74
|
- Users can check their total points or the points of any player.
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
## 🧪 Tests
|
|
77
77
|
|
|
78
78
|
This project includes integration tests that interact with the contract deployed in the Studio. These tests cover the main functionalities of the Football Bets contract:
|
|
79
79
|
|
|
@@ -84,7 +84,7 @@ This project includes integration tests that interact with the contract deployed
|
|
|
84
84
|
|
|
85
85
|
The tests simulate real-world interactions with the contract, ensuring that it behaves correctly under various scenarios. They use the GenLayer Studio to deploy and interact with the contract, providing a comprehensive check of the contract's functionality in a controlled environment.
|
|
86
86
|
|
|
87
|
-
To run the tests, use the `
|
|
87
|
+
To run the tests, use the `gltest` command as mentioned in the "Steps to run this example" section.
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
## 💬 Community
|
|
@@ -5,6 +5,7 @@ from dataclasses import dataclass
|
|
|
5
5
|
from genlayer import *
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
@allow_storage
|
|
8
9
|
@dataclass
|
|
9
10
|
class Bet:
|
|
10
11
|
id: str
|
|
@@ -18,8 +19,7 @@ class Bet:
|
|
|
18
19
|
real_score: str
|
|
19
20
|
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
class FootballBets:
|
|
22
|
+
class FootballBets(gl.Contract):
|
|
23
23
|
bets: TreeMap[Address, TreeMap[str, Bet]]
|
|
24
24
|
points: TreeMap[Address, u256]
|
|
25
25
|
|
|
@@ -67,7 +67,7 @@ This result should be perfectly parsable by a JSON parser without errors.
|
|
|
67
67
|
# if int(match_status["winner"]) > -1:
|
|
68
68
|
# raise Exception("Game already finished")
|
|
69
69
|
|
|
70
|
-
sender_address = gl.message.
|
|
70
|
+
sender_address = gl.message.sender_address
|
|
71
71
|
|
|
72
72
|
bet_id = f"{game_date}_{team1}_{team2}".lower()
|
|
73
73
|
if sender_address in self.bets and bet_id in self.bets[sender_address]:
|
|
@@ -88,10 +88,10 @@ This result should be perfectly parsable by a JSON parser without errors.
|
|
|
88
88
|
|
|
89
89
|
@gl.public.write
|
|
90
90
|
def resolve_bet(self, bet_id: str) -> None:
|
|
91
|
-
if self.bets[gl.message.
|
|
91
|
+
if self.bets[gl.message.sender_address][bet_id].has_resolved:
|
|
92
92
|
raise Exception("Bet already resolved")
|
|
93
93
|
|
|
94
|
-
bet = self.bets[gl.message.
|
|
94
|
+
bet = self.bets[gl.message.sender_address][bet_id]
|
|
95
95
|
bet_status = self._check_match(bet.resolution_url, bet.team1, bet.team2)
|
|
96
96
|
|
|
97
97
|
if int(bet_status["winner"]) < 0:
|
|
@@ -102,9 +102,9 @@ This result should be perfectly parsable by a JSON parser without errors.
|
|
|
102
102
|
bet.real_score = bet_status["score"]
|
|
103
103
|
|
|
104
104
|
if bet.real_winner == bet.predicted_winner:
|
|
105
|
-
if gl.message.
|
|
106
|
-
self.points[gl.message.
|
|
107
|
-
self.points[gl.message.
|
|
105
|
+
if gl.message.sender_address not in self.points:
|
|
106
|
+
self.points[gl.message.sender_address] = 0
|
|
107
|
+
self.points[gl.message.sender_address] += 1
|
|
108
108
|
|
|
109
109
|
@gl.public.view
|
|
110
110
|
def get_bets(self) -> dict:
|
|
@@ -116,4 +116,4 @@ This result should be perfectly parsable by a JSON parser without errors.
|
|
|
116
116
|
|
|
117
117
|
@gl.public.view
|
|
118
118
|
def get_player_points(self, player_address: str) -> int:
|
|
119
|
-
return self.points.get(Address(player_address), 0)
|
|
119
|
+
return self.points.get(Address(player_address), 0)
|
|
@@ -22,9 +22,14 @@ export default async function main(client: GenLayerClient<any>) {
|
|
|
22
22
|
retries: 200,
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
if (receipt.consensus_data?.leader_receipt?.execution_result !== "SUCCESS") {
|
|
25
|
+
if (receipt.consensus_data?.leader_receipt[0]?.execution_result !== "SUCCESS") {
|
|
26
26
|
throw new Error(`Deployment failed. Receipt: ${JSON.stringify(receipt)}`);
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
console.log("\n Contract deployed successfully.", {
|
|
30
|
+
"Transaction Hash": deployTransaction,
|
|
31
|
+
"Contract Address": receipt.data?.contract_address,
|
|
32
|
+
});
|
|
28
33
|
} catch (error) {
|
|
29
34
|
throw new Error((`Error during deployment:, ${error}`));
|
|
30
35
|
}
|
|
@@ -45,8 +45,8 @@ test_football_bets_win_unresolved = {
|
|
|
45
45
|
"has_resolved": False,
|
|
46
46
|
"id": "2024-06-20_spain_italy",
|
|
47
47
|
"predicted_winner": "1",
|
|
48
|
-
"real_score":
|
|
49
|
-
"real_winner":
|
|
48
|
+
"real_score": '',
|
|
49
|
+
"real_winner": '',
|
|
50
50
|
"resolution_url": "https://www.bbc.com/sport/football/scores-fixtures/2024-06-20",
|
|
51
51
|
"team1": "Spain",
|
|
52
52
|
"team2": "Italy",
|
|
@@ -73,8 +73,8 @@ test_football_bets_draw_unresolved = {
|
|
|
73
73
|
"has_resolved": False,
|
|
74
74
|
"id": "2024-06-20_denmark_england",
|
|
75
75
|
"predicted_winner": "0",
|
|
76
|
-
"real_score":
|
|
77
|
-
"real_winner":
|
|
76
|
+
"real_score": '',
|
|
77
|
+
"real_winner": '',
|
|
78
78
|
"resolution_url": "https://www.bbc.com/sport/football/scores-fixtures/2024-06-20",
|
|
79
79
|
"team1": "Denmark",
|
|
80
80
|
"team2": "England",
|
|
@@ -101,8 +101,8 @@ test_football_bets_unsuccess_unresolved = {
|
|
|
101
101
|
"has_resolved": False,
|
|
102
102
|
"id": "2024-06-20_spain_italy",
|
|
103
103
|
"predicted_winner": "2",
|
|
104
|
-
"real_score":
|
|
105
|
-
"real_winner":
|
|
104
|
+
"real_score": '',
|
|
105
|
+
"real_winner": '',
|
|
106
106
|
"resolution_url": "https://www.bbc.com/sport/football/scores-fixtures/2024-06-20",
|
|
107
107
|
"team1": "Spain",
|
|
108
108
|
"team2": "Italy",
|
|
@@ -121,4 +121,4 @@ test_football_bets_unsuccess_resolved = {
|
|
|
121
121
|
"team1": "Spain",
|
|
122
122
|
"team2": "Italy",
|
|
123
123
|
}
|
|
124
|
-
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
from gltest import get_contract_factory, default_account
|
|
2
|
+
from gltest.helpers import load_fixture
|
|
3
|
+
from gltest.assertions import tx_execution_succeeded
|
|
4
|
+
from test.football_bets_get_contract_schema_for_code import (
|
|
5
|
+
test_football_bets_win_resolved,
|
|
6
|
+
test_football_bets_win_unresolved,
|
|
7
|
+
test_football_bets_draw_unresolved,
|
|
8
|
+
test_football_bets_draw_resolved,
|
|
9
|
+
test_football_bets_unsuccess_unresolved,
|
|
10
|
+
test_football_bets_unsuccess_resolved,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def deploy_contract():
|
|
15
|
+
factory = get_contract_factory("FootballBets")
|
|
16
|
+
contract = factory.deploy()
|
|
17
|
+
|
|
18
|
+
# Get Initial State
|
|
19
|
+
contract_all_points_state = contract.get_points(args=[])
|
|
20
|
+
assert contract_all_points_state == {}
|
|
21
|
+
|
|
22
|
+
contract_all_bets_state = contract.get_bets(args=[])
|
|
23
|
+
assert contract_all_bets_state == {}
|
|
24
|
+
return contract
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_football_bets_success_win():
|
|
28
|
+
# Contract Deploy
|
|
29
|
+
|
|
30
|
+
contract = load_fixture(deploy_contract)
|
|
31
|
+
|
|
32
|
+
# Create Successful Bet
|
|
33
|
+
create_bet_result = contract.create_bet(args=["2024-06-20", "Spain", "Italy", "1"])
|
|
34
|
+
assert tx_execution_succeeded(create_bet_result)
|
|
35
|
+
|
|
36
|
+
# Get Bets
|
|
37
|
+
get_bet_result = contract.get_bets(args=[])
|
|
38
|
+
assert get_bet_result == {
|
|
39
|
+
default_account.address: test_football_bets_win_unresolved
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
# Resolve Successful Bet
|
|
43
|
+
resolve_successful_bet_result = contract.resolve_bet(
|
|
44
|
+
args=["2024-06-20_spain_italy"],
|
|
45
|
+
wait_interval=10000, # 10000 ms = 10 seconds
|
|
46
|
+
wait_retries=15,
|
|
47
|
+
)
|
|
48
|
+
assert tx_execution_succeeded(resolve_successful_bet_result)
|
|
49
|
+
|
|
50
|
+
# Get Bets
|
|
51
|
+
get_bet_result = contract.get_bets(args=[])
|
|
52
|
+
assert get_bet_result == {default_account.address: test_football_bets_win_resolved}
|
|
53
|
+
|
|
54
|
+
# Get Points
|
|
55
|
+
get_points_result = contract.get_points(args=[])
|
|
56
|
+
assert get_points_result == {default_account.address: 1}
|
|
57
|
+
|
|
58
|
+
# Get Player Points
|
|
59
|
+
get_player_points_result = contract.get_player_points(
|
|
60
|
+
args=[default_account.address]
|
|
61
|
+
)
|
|
62
|
+
assert get_player_points_result == 1
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_football_bets_draw_success():
|
|
66
|
+
# Contract Deploy
|
|
67
|
+
contract = load_fixture(deploy_contract)
|
|
68
|
+
|
|
69
|
+
# Create Successful Bet
|
|
70
|
+
create_bet_result = contract.create_bet(
|
|
71
|
+
args=["2024-06-20", "Denmark", "England", "0"]
|
|
72
|
+
)
|
|
73
|
+
assert tx_execution_succeeded(create_bet_result)
|
|
74
|
+
|
|
75
|
+
# Get Bets
|
|
76
|
+
get_bet_result = contract.get_bets(args=[])
|
|
77
|
+
assert get_bet_result == {
|
|
78
|
+
default_account.address: test_football_bets_draw_unresolved
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Resolve Successful Bet
|
|
82
|
+
resolve_successful_bet_result = contract.resolve_bet(
|
|
83
|
+
args=["2024-06-20_denmark_england"],
|
|
84
|
+
wait_interval=10000, # 10000 ms = 10 seconds
|
|
85
|
+
wait_retries=15,
|
|
86
|
+
)
|
|
87
|
+
assert tx_execution_succeeded(resolve_successful_bet_result)
|
|
88
|
+
|
|
89
|
+
# Get Bets
|
|
90
|
+
get_bet_result = contract.get_bets(args=[])
|
|
91
|
+
assert get_bet_result == {default_account.address: test_football_bets_draw_resolved}
|
|
92
|
+
|
|
93
|
+
# Get Points
|
|
94
|
+
get_points_result = contract.get_points(args=[])
|
|
95
|
+
assert get_points_result == {default_account.address: 1}
|
|
96
|
+
|
|
97
|
+
# Get Player Points
|
|
98
|
+
get_player_points_result = contract.get_player_points(
|
|
99
|
+
args=[default_account.address]
|
|
100
|
+
)
|
|
101
|
+
assert get_player_points_result == 1
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_football_bets_unsuccess():
|
|
105
|
+
# Contract Deploy
|
|
106
|
+
contract = load_fixture(deploy_contract)
|
|
107
|
+
|
|
108
|
+
# Create Successful Bet
|
|
109
|
+
create_bet_result = contract.create_bet(args=["2024-06-20", "Spain", "Italy", "2"])
|
|
110
|
+
assert tx_execution_succeeded(create_bet_result)
|
|
111
|
+
|
|
112
|
+
# Get Bets
|
|
113
|
+
get_bet_result = contract.get_bets(args=[])
|
|
114
|
+
assert get_bet_result == {
|
|
115
|
+
default_account.address: test_football_bets_unsuccess_unresolved
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
# Resolve Successful Bet
|
|
119
|
+
resolve_successful_bet_result = contract.resolve_bet(
|
|
120
|
+
args=["2024-06-20_spain_italy"],
|
|
121
|
+
wait_interval=10000, # 10000 ms = 10 seconds
|
|
122
|
+
wait_retries=15,
|
|
123
|
+
)
|
|
124
|
+
assert tx_execution_succeeded(resolve_successful_bet_result)
|
|
125
|
+
|
|
126
|
+
# Get Bets
|
|
127
|
+
get_bet_result = contract.get_bets(args=[])
|
|
128
|
+
assert get_bet_result == {
|
|
129
|
+
default_account.address: test_football_bets_unsuccess_resolved
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
# Get Points
|
|
133
|
+
get_points_result = contract.get_points(args=[])
|
|
134
|
+
assert get_points_result == {}
|
|
135
|
+
|
|
136
|
+
# Get Player Points
|
|
137
|
+
get_player_points_result = contract.get_player_points(
|
|
138
|
+
args=[default_account.address]
|
|
139
|
+
)
|
|
140
|
+
assert get_player_points_result == 0
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# tests/e2e/test_wizard_of_coin.py
|
|
2
|
-
|
|
3
|
-
from tools.accounts import create_new_account
|
|
4
|
-
from tools.request import (
|
|
5
|
-
deploy_intelligent_contract,
|
|
6
|
-
send_transaction,
|
|
7
|
-
call_contract_method,
|
|
8
|
-
payload,
|
|
9
|
-
post_request,
|
|
10
|
-
)
|
|
11
|
-
from tools.structure import execute_icontract_function_response_structure
|
|
12
|
-
from tools.response import (
|
|
13
|
-
assert_dict_struct,
|
|
14
|
-
assert_dict_exact,
|
|
15
|
-
has_success_status,
|
|
16
|
-
)
|
|
17
|
-
from test.football_bets_get_contract_schema_for_code import (
|
|
18
|
-
football_bets_contract_schema,
|
|
19
|
-
test_football_bets_win_resolved,
|
|
20
|
-
test_football_bets_win_unresolved,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def test_football_bets_success():
|
|
25
|
-
# Account
|
|
26
|
-
account_1 = create_new_account()
|
|
27
|
-
# Validators - not needed for studio.genlayer.com
|
|
28
|
-
# result = post_request(
|
|
29
|
-
# payload("sim_createRandomValidators", 5, 8, 12, ["openai"], ["gpt-4o"])
|
|
30
|
-
# ).json()
|
|
31
|
-
# assert has_success_status(result)
|
|
32
|
-
|
|
33
|
-
# Contract Schema
|
|
34
|
-
contract_code = open("contracts/football_bets.py", "r").read()
|
|
35
|
-
result_schema = post_request(
|
|
36
|
-
payload("gen_getContractSchemaForCode", contract_code)
|
|
37
|
-
).json()
|
|
38
|
-
assert has_success_status(result_schema)
|
|
39
|
-
assert_dict_exact(result_schema, football_bets_contract_schema)
|
|
40
|
-
|
|
41
|
-
# Contract Deploy
|
|
42
|
-
contract_address, transaction_response_deploy = deploy_intelligent_contract(
|
|
43
|
-
account_1,
|
|
44
|
-
contract_code,
|
|
45
|
-
"{}",
|
|
46
|
-
)
|
|
47
|
-
assert has_success_status(transaction_response_deploy)
|
|
48
|
-
|
|
49
|
-
# Get Initial State
|
|
50
|
-
contract_all_points_state = call_contract_method(
|
|
51
|
-
contract_address, account_1, "get_points", []
|
|
52
|
-
)
|
|
53
|
-
assert contract_all_points_state == {}
|
|
54
|
-
|
|
55
|
-
contract_all_bets_state = call_contract_method(
|
|
56
|
-
contract_address, account_1, "get_bets", []
|
|
57
|
-
)
|
|
58
|
-
assert contract_all_bets_state == {}
|
|
59
|
-
|
|
60
|
-
# Create Successful Bet
|
|
61
|
-
create_successful_bet_result = send_transaction(
|
|
62
|
-
account_1,
|
|
63
|
-
contract_address,
|
|
64
|
-
"create_bet",
|
|
65
|
-
["2024-06-20", "Denmark", "England", "0"],
|
|
66
|
-
)
|
|
67
|
-
assert has_success_status(create_successful_bet_result)
|
|
68
|
-
assert_dict_struct(
|
|
69
|
-
create_successful_bet_result,
|
|
70
|
-
execute_icontract_function_response_structure,
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
# Get Bets
|
|
74
|
-
get_bet_result = call_contract_method(contract_address, account_1, "get_bets", [])
|
|
75
|
-
assert get_bet_result == {account_1.address: test_football_bets_win_unresolved}
|
|
76
|
-
|
|
77
|
-
# Resolve Successful Bet
|
|
78
|
-
resolve_successful_bet_result = send_transaction(
|
|
79
|
-
account_1,
|
|
80
|
-
contract_address,
|
|
81
|
-
"resolve_bet",
|
|
82
|
-
["2024-06-20_denmark_england"],
|
|
83
|
-
)
|
|
84
|
-
assert has_success_status(resolve_successful_bet_result)
|
|
85
|
-
assert_dict_struct(
|
|
86
|
-
resolve_successful_bet_result,
|
|
87
|
-
execute_icontract_function_response_structure,
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
# Get Bets
|
|
91
|
-
get_bet_result = call_contract_method(contract_address, account_1, "get_bets", [])
|
|
92
|
-
assert get_bet_result == {account_1.address: test_football_bets_win_resolved}
|
|
93
|
-
|
|
94
|
-
# Get Points
|
|
95
|
-
get_points_result = call_contract_method(
|
|
96
|
-
contract_address, account_1, "get_points", []
|
|
97
|
-
)
|
|
98
|
-
assert get_points_result == {account_1.address: 1}
|
|
99
|
-
|
|
100
|
-
# Get Player Points
|
|
101
|
-
get_player_points_result = call_contract_method(
|
|
102
|
-
contract_address, account_1, "get_player_points", [account_1.address]
|
|
103
|
-
)
|
|
104
|
-
assert get_player_points_result == 1
|
|
105
|
-
|
|
106
|
-
# Delete Validators - not needed for studio.genlayer.com
|
|
107
|
-
# delete_validators_result = post_request(payload("sim_deleteAllValidators")).json()
|
|
108
|
-
# assert has_success_status(delete_validators_result)
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# tests/e2e/test_wizard_of_coin.py
|
|
2
|
-
|
|
3
|
-
from tools.accounts import create_new_account
|
|
4
|
-
from tools.request import (
|
|
5
|
-
deploy_intelligent_contract,
|
|
6
|
-
send_transaction,
|
|
7
|
-
call_contract_method,
|
|
8
|
-
payload,
|
|
9
|
-
post_request,
|
|
10
|
-
)
|
|
11
|
-
from tools.structure import execute_icontract_function_response_structure
|
|
12
|
-
from tools.response import (
|
|
13
|
-
assert_dict_struct,
|
|
14
|
-
assert_dict_exact,
|
|
15
|
-
has_success_status,
|
|
16
|
-
)
|
|
17
|
-
from test.football_bets_get_contract_schema_for_code import (
|
|
18
|
-
football_bets_contract_schema,
|
|
19
|
-
test_football_bets_win_unresolved,
|
|
20
|
-
test_football_bets_win_resolved,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def test_football_bets_success():
|
|
25
|
-
# Account
|
|
26
|
-
account_1 = create_new_account()
|
|
27
|
-
# Validators - not needed for studio.genlayer.com
|
|
28
|
-
# result = post_request(
|
|
29
|
-
# payload("sim_createRandomValidators", 5, 8, 12, ["openai"], ["gpt-4o"])
|
|
30
|
-
# ).json()
|
|
31
|
-
# assert has_success_status(result)
|
|
32
|
-
|
|
33
|
-
# Contract Schema
|
|
34
|
-
contract_code = open("contracts/football_bet_market.py", "r").read()
|
|
35
|
-
result_schema = post_request(
|
|
36
|
-
payload("gen_getContractSchemaForCode", contract_code)
|
|
37
|
-
).json()
|
|
38
|
-
assert has_success_status(result_schema)
|
|
39
|
-
assert_dict_exact(result_schema, football_bets_contract_schema)
|
|
40
|
-
|
|
41
|
-
# Contract Deploy
|
|
42
|
-
contract_address, transaction_response_deploy = deploy_intelligent_contract(
|
|
43
|
-
account_1,
|
|
44
|
-
contract_code,
|
|
45
|
-
"{}",
|
|
46
|
-
)
|
|
47
|
-
assert has_success_status(transaction_response_deploy)
|
|
48
|
-
|
|
49
|
-
# Get Initial State
|
|
50
|
-
contract_all_points_state = call_contract_method(
|
|
51
|
-
contract_address, account_1, "get_points", []
|
|
52
|
-
)
|
|
53
|
-
assert contract_all_points_state == {}
|
|
54
|
-
|
|
55
|
-
contract_all_bets_state = call_contract_method(
|
|
56
|
-
contract_address, account_1, "get_bets", []
|
|
57
|
-
)
|
|
58
|
-
assert contract_all_bets_state == {}
|
|
59
|
-
|
|
60
|
-
# Create Successful Bet
|
|
61
|
-
create_successful_bet_result = send_transaction(
|
|
62
|
-
account_1,
|
|
63
|
-
contract_address,
|
|
64
|
-
"create_bet",
|
|
65
|
-
["2024-06-20", "Spain", "Italy", "1"],
|
|
66
|
-
)
|
|
67
|
-
assert has_success_status(create_successful_bet_result)
|
|
68
|
-
assert_dict_struct(
|
|
69
|
-
create_successful_bet_result,
|
|
70
|
-
execute_icontract_function_response_structure,
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
# Get Bets
|
|
74
|
-
get_bet_result = call_contract_method(contract_address, account_1, "get_bets", [])
|
|
75
|
-
print("~ ~ ~ ~ ~ get_bet_result", get_bet_result)
|
|
76
|
-
assert get_bet_result == {account_1.address: test_football_bets_win_unresolved}
|
|
77
|
-
|
|
78
|
-
# Resolve Successful Bet
|
|
79
|
-
resolve_successful_bet_result = send_transaction(
|
|
80
|
-
account_1, contract_address, "resolve_bet", ["2024-06-20_spain_italy"]
|
|
81
|
-
)
|
|
82
|
-
assert has_success_status(resolve_successful_bet_result)
|
|
83
|
-
assert_dict_struct(
|
|
84
|
-
resolve_successful_bet_result,
|
|
85
|
-
execute_icontract_function_response_structure,
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
# Get Bets
|
|
89
|
-
get_bet_result = call_contract_method(contract_address, account_1, "get_bets", [])
|
|
90
|
-
assert get_bet_result == {account_1.address: test_football_bets_win_resolved}
|
|
91
|
-
|
|
92
|
-
# Get Points
|
|
93
|
-
get_points_result = call_contract_method(
|
|
94
|
-
contract_address, account_1, "get_points", []
|
|
95
|
-
)
|
|
96
|
-
assert get_points_result == {account_1.address: 1}
|
|
97
|
-
|
|
98
|
-
# Get Player Points
|
|
99
|
-
get_player_points_result = call_contract_method(
|
|
100
|
-
contract_address, account_1, "get_player_points", [account_1.address]
|
|
101
|
-
)
|
|
102
|
-
assert get_player_points_result == 1
|
|
103
|
-
|
|
104
|
-
# Delete Validators - not needed for studio.genlayer.com
|
|
105
|
-
# delete_validators_result = post_request(payload("sim_deleteAllValidators")).json()
|
|
106
|
-
# assert has_success_status(delete_validators_result)
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
# tests/e2e/test_wizard_of_coin.py
|
|
2
|
-
|
|
3
|
-
from tools.accounts import create_new_account
|
|
4
|
-
from tools.request import (
|
|
5
|
-
deploy_intelligent_contract,
|
|
6
|
-
send_transaction,
|
|
7
|
-
call_contract_method,
|
|
8
|
-
payload,
|
|
9
|
-
post_request,
|
|
10
|
-
)
|
|
11
|
-
from tools.structure import execute_icontract_function_response_structure
|
|
12
|
-
from tools.response import (
|
|
13
|
-
assert_dict_struct,
|
|
14
|
-
assert_dict_exact,
|
|
15
|
-
has_success_status,
|
|
16
|
-
)
|
|
17
|
-
from test.football_bets_get_contract_schema_for_code import (
|
|
18
|
-
football_bets_contract_schema,
|
|
19
|
-
test_football_bets_unsuccess_unresolved,
|
|
20
|
-
test_football_bets_unsuccess_resolved,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def test_football_bets_unsuccess():
|
|
25
|
-
# Account
|
|
26
|
-
account_1 = create_new_account()
|
|
27
|
-
# Validators - not needed for studio.genlayer.com
|
|
28
|
-
# result = post_request(
|
|
29
|
-
# payload("sim_createRandomValidators", 5, 8, 12, ["openai"], ["gpt-4o"])
|
|
30
|
-
# ).json()
|
|
31
|
-
# assert has_success_status(result)
|
|
32
|
-
|
|
33
|
-
# Contract Schema
|
|
34
|
-
contract_code = open("contracts/football_bet_market.py", "r").read()
|
|
35
|
-
result_schema = post_request(
|
|
36
|
-
payload("gen_getContractSchemaForCode", contract_code)
|
|
37
|
-
).json()
|
|
38
|
-
assert has_success_status(result_schema)
|
|
39
|
-
assert_dict_exact(result_schema, football_bets_contract_schema)
|
|
40
|
-
|
|
41
|
-
# Contract Deploy
|
|
42
|
-
contract_address, transaction_response_deploy = deploy_intelligent_contract(
|
|
43
|
-
account_1,
|
|
44
|
-
contract_code,
|
|
45
|
-
"{}",
|
|
46
|
-
)
|
|
47
|
-
assert has_success_status(transaction_response_deploy)
|
|
48
|
-
|
|
49
|
-
# Get Initial State
|
|
50
|
-
contract_all_points_state = call_contract_method(
|
|
51
|
-
contract_address, account_1, "get_points", []
|
|
52
|
-
)
|
|
53
|
-
assert contract_all_points_state == {}
|
|
54
|
-
|
|
55
|
-
contract_all_bets_state = call_contract_method(
|
|
56
|
-
contract_address, account_1, "get_bets", []
|
|
57
|
-
)
|
|
58
|
-
assert contract_all_bets_state == {}
|
|
59
|
-
|
|
60
|
-
# Create Successful Bet
|
|
61
|
-
create_successful_bet_result = send_transaction(
|
|
62
|
-
account_1,
|
|
63
|
-
contract_address,
|
|
64
|
-
"create_bet",
|
|
65
|
-
["2024-06-20", "Spain", "Italy", "2"],
|
|
66
|
-
)
|
|
67
|
-
assert has_success_status(create_successful_bet_result)
|
|
68
|
-
assert_dict_struct(
|
|
69
|
-
create_successful_bet_result,
|
|
70
|
-
execute_icontract_function_response_structure,
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
# Get Bets
|
|
74
|
-
get_bet_result = call_contract_method(contract_address, account_1, "get_bets", [])
|
|
75
|
-
assert get_bet_result == {
|
|
76
|
-
account_1.address: test_football_bets_unsuccess_unresolved
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
# Resolve Successful Bet
|
|
80
|
-
resolve_successful_bet_result = send_transaction(
|
|
81
|
-
account_1, contract_address, "resolve_bet", ["2024-06-20_spain_italy"]
|
|
82
|
-
)
|
|
83
|
-
assert has_success_status(resolve_successful_bet_result)
|
|
84
|
-
assert_dict_struct(
|
|
85
|
-
resolve_successful_bet_result,
|
|
86
|
-
execute_icontract_function_response_structure,
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
# Get Bets
|
|
90
|
-
get_bet_result = call_contract_method(contract_address, account_1, "get_bets", [])
|
|
91
|
-
assert get_bet_result == {account_1.address: test_football_bets_unsuccess_resolved}
|
|
92
|
-
|
|
93
|
-
# Get Points
|
|
94
|
-
get_points_result = call_contract_method(
|
|
95
|
-
contract_address, account_1, "get_points", []
|
|
96
|
-
)
|
|
97
|
-
assert get_points_result == {}
|
|
98
|
-
|
|
99
|
-
# Get Player Points
|
|
100
|
-
get_player_points_result = call_contract_method(
|
|
101
|
-
contract_address, account_1, "get_player_points", [account_1.address]
|
|
102
|
-
)
|
|
103
|
-
assert get_player_points_result == 0
|
|
104
|
-
|
|
105
|
-
# Delete Validators - not needed for studio.genlayer.com
|
|
106
|
-
# delete_validators_result = post_request(payload("sim_deleteAllValidators")).json()
|
|
107
|
-
# assert has_success_status(delete_validators_result)
|