Skip to content

Commit 6ad556b

Browse files
chore: refactor contracts helper & fix utils comment
1 parent f7e4413 commit 6ad556b

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

src/mappings/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ export async function trackUnprocessed(error: Error, primitives: Primitives): Pr
9292
block.block.id : error.stack;
9393
sha256.write(hashInput);
9494
sha256.end();
95-
// NB: ID is base64 encoded representation of the sha256 of `raw`.
95+
// NB: ID is base64 encoded representation of the sha256 of either:
96+
// 1. the conventional ID of the "highest-level" primitive available or
97+
// 2. the error stacktrace, if none are available (i.e. handle block error)
9698
const id = sha256.read().toString("base64");
9799
const eventId = event ? messageId(event) : undefined;
98100
const _messageId = event ? messageId(event) : undefined;

tests/helpers/contracts.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,54 @@ class BridgeContractConfig:
3636
)
3737

3838

39+
def ensure_contract(name: str, url: str) -> str:
40+
contract_path = f".contract/{name}.wasm"
41+
if not os.path.exists(".contract"):
42+
os.mkdir(".contract")
43+
try:
44+
temp = open(contract_path, "rb")
45+
temp.close()
46+
except OSError:
47+
contract_request = requests.get(url)
48+
with open(contract_path, "wb") as file:
49+
file.write(contract_request.content)
50+
finally:
51+
return contract_path
52+
53+
54+
class DeployTestContract(LedgerContract):
55+
56+
def __init__(self, client: LedgerClient, admin: Wallet):
57+
""" Using a slightly older version of CW20 contract as a test contract - as this will still be classified as the
58+
CW20 interface, but is different enough to allow a unique store_code message during testing."""
59+
url = "https://github.com/CosmWasm/cw-plus/releases/download/v0.14.0/cw20_base.wasm"
60+
contract_path = ensure_contract("test_contract", url)
61+
super().__init__(contract_path, client)
62+
63+
self.deploy({
64+
"name": "test coin",
65+
"symbol": "TEST",
66+
"decimals": 6,
67+
"initial_balances": [{
68+
"amount": "3000000000000000000000000",
69+
"address": str(admin.address())
70+
}],
71+
"mint": {"minter": str(admin.address())}
72+
},
73+
admin,
74+
store_gas_limit=3000000
75+
)
76+
77+
3978
class Cw20Contract(LedgerContract):
4079
admin: Wallet = None
4180
gas_limit: int = 3000000
4281

4382
def __init__(self, client: LedgerClient, admin: Wallet):
4483
self.admin = admin
4584
url = "https://github.com/CosmWasm/cw-plus/releases/download/v0.16.0/cw20_base.wasm"
46-
if not os.path.exists(".contract"):
47-
os.mkdir(".contract")
48-
try:
49-
temp = open(".contract/cw20.wasm", "rb")
50-
temp.close()
51-
except:
52-
contract_request = requests.get(url)
53-
with open(".contract/cw20.wasm", "wb") as file:
54-
file.write(contract_request.content)
55-
56-
super().__init__(".contract/cw20.wasm", client)
85+
contract_path = ensure_contract("cw20", url)
86+
super().__init__(contract_path, client)
5787

5888
def _store(self) -> int:
5989
assert self.admin is not None
@@ -81,20 +111,12 @@ def _instantiate(self, code_id) -> Address:
81111

82112
class BridgeContract(LedgerContract):
83113
def __init__(self, client: LedgerClient, admin: Wallet, cfg: BridgeContractConfig):
84-
url = "https://github.com/fetchai/fetch-ethereum-bridge-v1/releases/download/v0.2.0/bridge.wasm"
85-
if not os.path.exists(".contract"):
86-
os.mkdir(".contract")
87-
try:
88-
temp = open(".contract/bridge.wasm", "rb")
89-
temp.close()
90-
except:
91-
contract_request = requests.get(url)
92-
with open(".contract/bridge.wasm", "wb") as file:
93-
file.write(contract_request.content)
114+
url = "https://github.com/fetchai/contract-agent-almanac/releases/download/v0.1.0/contract_agent_almanac.wasm"
115+
contract_path = ensure_contract("bridge", url)
94116

95117
# LedgerContract will attempt to discover any existing contract having the same bytecode hash
96118
# see https://github.com/fetchai/cosmpy/blob/master/cosmpy/aerial/contract/__init__.py#L74
97-
super().__init__(".contract/bridge.wasm", client)
119+
super().__init__(contract_path, client)
98120

99121
# deploy will store the contract only if no existing contracts was found during init.
100122
# and it will instantiate the contract only if contract.address is None

0 commit comments

Comments
 (0)