-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added value validation (0.5TON < val < 1TON); Added set source item c…
…ode op; Non-sequential op codes; Non-empty set code validation (#2) * added value validation * - * - * e2e * fixed tests
- Loading branch information
1 parent
ffe3d9b
commit 80f8324
Showing
20 changed files
with
750 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
# TON SRC Contracts | ||
nft-based contracts for registering the sources data url for a given code cell hash | ||
nft-based contracts for registering the sources data url for a given code cell hash | ||
|
||
## E2E tests | ||
(e2e.ts in test/e2e) | ||
1. Pre-deploy (using `npm run build && npm run deploy`) the sources registry contract -> change min_tons in sources_registry.fc to a small amount, otherwise tests are too costly. | ||
2. Provide two mnemonics via .env | ||
3. Flows carried out: | ||
* (Sender: wallet1) Change admin from wallet1 to wallet2 | ||
* (Sender: wallet2) Change verifier address from actual to zero address; then revert to actual | ||
* (Sender: wallet2) Set code to `sources-registry-only-set-code.fc`; then revert to original | ||
* (Sender: wallet2) Change admin from wallet2 to wallet1 | ||
* (Sender: wallet1) Set source item code to `...?.fc`; then revert to original |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
build/verifier-registry.deploy.ts → build/verifier-registry.__deploy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
;; | ||
;; Source item smart contract - DUMMY FOR TESTS | ||
;; | ||
|
||
#pragma version >=0.2.0; | ||
#include "imports/stdlib.fc"; | ||
|
||
const int error::access_denied = 401; | ||
const int error::unknown_op = 0xffff; | ||
|
||
;; | ||
;; Storage | ||
;; | ||
;; uint256 verifier_id | ||
;; uint256 verified_code_cell_hash | ||
;; MsgAddressInt source_item_registry | ||
;; cell content | ||
;; | ||
(int, int, int, slice, cell) load_data() { | ||
slice ds = get_data().begin_parse(); | ||
var (verifier_id, verified_code_cell_hash, source_item_registry) = (ds~load_uint(256), ds~load_uint(256), ds~load_msg_addr()); | ||
if (ds.slice_refs() > 0) { | ||
return (-1, verifier_id, verified_code_cell_hash, source_item_registry, ds~load_ref()); | ||
} else { | ||
return (0, verifier_id, verified_code_cell_hash, source_item_registry, null()); ;; not initialized yet | ||
} | ||
} | ||
|
||
() store_data(int verifier_id, int verified_code_cell_hash, slice source_item_registry, cell content) impure { | ||
set_data( | ||
begin_cell() | ||
.store_uint(verifier_id, 256) | ||
.store_uint(verified_code_cell_hash, 256) | ||
.store_slice(source_item_registry) | ||
.store_ref(content) | ||
.end_cell() | ||
); | ||
} | ||
|
||
() recv_internal(int my_balance, int msg_value, cell in_msg_full, slice in_msg_body) impure { | ||
if (in_msg_body.slice_empty?()) { ;; ignore empty messages | ||
return (); | ||
} | ||
|
||
slice cs = in_msg_full.begin_parse(); | ||
int flags = cs~load_uint(4); | ||
|
||
if (flags & 1) { ;; ignore all bounced messages | ||
return (); | ||
} | ||
slice sender_address = cs~load_msg_addr(); | ||
|
||
(int init?, int verifier_id, int verified_code_cell_hash, slice source_item_registry, cell content) = load_data(); | ||
if (~ init?) { | ||
throw_unless(error::access_denied, equal_slices(source_item_registry, sender_address)); | ||
store_data(verifier_id, verified_code_cell_hash, source_item_registry, begin_cell().store_slice(in_msg_body).end_cell()); | ||
return (); | ||
} | ||
|
||
throw(error::unknown_op); | ||
} | ||
|
||
;; | ||
;; GET Methods | ||
;; | ||
(int, int, int, slice, cell) get_dummy_data() method_id { | ||
(int init?, int verifier_id, int verified_code_cell_hash, slice source_item_registry, cell content) = load_data(); | ||
return (init?, verifier_id, verified_code_cell_hash, source_item_registry, content); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
;; DUMMY CODE for tests only | ||
|
||
;; storage scheme | ||
;; storage#_ verifier_registry_address:MsgAddress | ||
;; source_item_code:^Cell | ||
;; = Storage; | ||
#pragma version >=0.2.0; | ||
#include "imports/stdlib.fc"; | ||
#include "imports/params.fc"; | ||
|
||
() recv_internal(int msg_value, cell in_msg_full, slice in_msg_body) impure { | ||
if (in_msg_body.slice_empty?()) { ;; ignore empty messages | ||
return (); | ||
} | ||
slice cs = in_msg_full.begin_parse(); | ||
int flags = cs~load_uint(4); | ||
|
||
if (flags & 1) { ;; ignore all bounced messages | ||
return (); | ||
} | ||
slice sender_address = cs~load_msg_addr(); | ||
|
||
int op = in_msg_body~load_uint(32); | ||
int query_id = in_msg_body~load_uint(64); | ||
|
||
if (op == 9988) { | ||
cell new_code = in_msg_body~load_ref(); | ||
in_msg_body.end_parse(); | ||
set_code(new_code); | ||
return (); | ||
} | ||
|
||
throw(203); | ||
} | ||
|
||
int get_am_i_replaced() method_id { | ||
return 742; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
UQA5NWl5eH6KvxwnMBCj7vDbb-Xebok-pWGfFuHhq1zMxmv5