Skip to content

Commit

Permalink
chore: refactor contracts helper & fix utils comment
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Dec 1, 2022
1 parent 6d751fb commit 2046443
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
4 changes: 3 additions & 1 deletion src/mappings/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export async function trackUnprocessed(error: Error, primitives: Primitives): Pr
block.block.id : error.stack;
sha256.write(hashInput);
sha256.end();
// NB: ID is base64 encoded representation of the sha256 of `raw`.
// NB: ID is base64 encoded representation of the sha256 of either:
// 1. the conventional ID of the "highest-level" primitive available or
// 2. the error stacktrace, if none are available (i.e. handle block error)
const id = sha256.read().toString("base64");
const eventId = event ? messageId(event) : undefined;
const _messageId = event ? messageId(event) : undefined;
Expand Down
55 changes: 22 additions & 33 deletions tests/helpers/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,29 @@ class BridgeContractConfig:
)


def ensure_contract(name: str, url: str) -> str:
contract_path = f".contract/{name}.wasm"
if not os.path.exists(".contract"):
os.mkdir(".contract")
try:
temp = open(contract_path, "rb")
temp.close()
except OSError:
contract_request = requests.get(url)
with open(contract_path, "wb") as file:
file.write(contract_request.content)
finally:
return contract_path


class DeployTestContract(LedgerContract):

def __init__(self, client: LedgerClient, admin: Wallet):
""" Using a slightly older version of CW20 contract as a test contract - as this will still be classified as the
CW20 interface, but is different enough to allow a unique store_code message during testing."""
url = "https://github.com/CosmWasm/cw-plus/releases/download/v0.14.0/cw20_base.wasm"
if not os.path.exists(".contract"):
os.mkdir(".contract")
try:
temp = open(".contract/test_contract.wasm", "rb")
temp.close()
except:
contract_request = requests.get(url)
with open(".contract/test_contract.wasm", "wb") as file:
file.write(contract_request.content)

super().__init__(".contract/test_contract.wasm", client)
contract_path = ensure_contract("test_contract", url)
super().__init__(contract_path, client)

self.deploy({
"name": "test coin",
Expand All @@ -71,17 +77,8 @@ def __init__(self, client: LedgerClient, admin: Wallet):
class Cw20Contract(LedgerContract):
def __init__(self, client: LedgerClient, admin: Wallet):
url = "https://github.com/CosmWasm/cw-plus/releases/download/v0.16.0/cw20_base.wasm"
if not os.path.exists(".contract"):
os.mkdir(".contract")
try:
temp = open(".contract/cw20.wasm", "rb")
temp.close()
except:
contract_request = requests.get(url)
with open(".contract/cw20.wasm", "wb") as file:
file.write(contract_request.content)

super().__init__(".contract/cw20.wasm", client)
contract_path = ensure_contract("cw20", url)
super().__init__(contract_path, client)

self.deploy({
"name": "test coin",
Expand All @@ -100,20 +97,12 @@ def __init__(self, client: LedgerClient, admin: Wallet):

class BridgeContract(LedgerContract):
def __init__(self, client: LedgerClient, admin: Wallet, cfg: BridgeContractConfig):
url = "https://github.com/fetchai/fetch-ethereum-bridge-v1/releases/download/v0.2.0/bridge.wasm"
if not os.path.exists(".contract"):
os.mkdir(".contract")
try:
temp = open(".contract/bridge.wasm", "rb")
temp.close()
except:
contract_request = requests.get(url)
with open(".contract/bridge.wasm", "wb") as file:
file.write(contract_request.content)
url = "https://github.com/fetchai/contract-agent-almanac/releases/download/v0.1.0/contract_agent_almanac.wasm"
contract_path = ensure_contract("bridge", url)

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

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

0 comments on commit 2046443

Please sign in to comment.