2021-10-10 15:37:26 +02:00
|
|
|
# standard imports
|
|
|
|
import os
|
2022-03-01 08:01:56 +01:00
|
|
|
import random
|
2021-10-11 12:27:51 +02:00
|
|
|
import tempfile
|
|
|
|
import unittest
|
|
|
|
|
2022-03-01 08:01:56 +01:00
|
|
|
from cic.contract.components.attachment import Attachment
|
|
|
|
from cic.contract.components.proof import Proof
|
|
|
|
from cic.contract.processor import ContractProcessor
|
2021-10-11 12:27:51 +02:00
|
|
|
|
|
|
|
# local imports
|
2022-03-01 08:01:56 +01:00
|
|
|
from cic.writers import KVWriter
|
|
|
|
|
|
|
|
# external imports
|
|
|
|
from hexathon import add_0x
|
2021-10-11 12:27:51 +02:00
|
|
|
|
2021-10-10 15:37:26 +02:00
|
|
|
test_base_dir = os.path.dirname(os.path.realpath(__file__))
|
2022-03-01 08:01:56 +01:00
|
|
|
test_data_dir = os.path.join(test_base_dir, "testdata")
|
2021-10-11 12:27:51 +02:00
|
|
|
|
2022-03-01 08:01:56 +01:00
|
|
|
proof_hash = "0f6fc017f29caf512c0feaaf83bc10614b488311cace2973dc248dc24b01e04f"
|
|
|
|
foo_hash = "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"
|
|
|
|
bar_hash = "fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9"
|
|
|
|
root_merged_hash = "2a27a488377c753fffea58ad535cfdacc2fcb5cf0ae495ec71d88e31757ec0c3"
|
|
|
|
root_unmerged_hash = "14dc271290eca763e99c2e7c21c541bded86fb803c6b01bac28cd367db34399c"
|
2021-10-11 19:13:21 +02:00
|
|
|
|
2021-10-11 12:27:51 +02:00
|
|
|
|
|
|
|
class TestCICBase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestCICBase, self).setUp()
|
|
|
|
random.seed(42)
|
|
|
|
|
2022-03-01 08:01:56 +01:00
|
|
|
f = open("/dev/urandom", "rb")
|
2021-11-29 15:39:16 +01:00
|
|
|
addresses = []
|
2022-03-01 08:01:56 +01:00
|
|
|
for _i in range(3):
|
2021-11-29 15:39:16 +01:00
|
|
|
address_bytes = f.read(32)
|
|
|
|
addresses.append(add_0x(address_bytes.hex()))
|
|
|
|
|
2022-03-01 08:01:56 +01:00
|
|
|
self.token_symbol = "FOO"
|
|
|
|
|
2021-11-29 15:44:09 +01:00
|
|
|
token_address_bytes = f.read(20)
|
|
|
|
token_index_address_bytes = f.read(20)
|
|
|
|
address_declarator_address_bytes = f.read(20)
|
|
|
|
|
|
|
|
self.token_address = add_0x(token_address_bytes.hex())
|
|
|
|
self.token_index_address = add_0x(token_index_address_bytes.hex())
|
|
|
|
self.address_declarator_address = add_0x(address_declarator_address_bytes.hex())
|
|
|
|
|
|
|
|
f.close()
|
2021-10-11 12:27:51 +02:00
|
|
|
|
2021-10-11 15:28:09 +02:00
|
|
|
self.outputs_dir = tempfile.mkdtemp()
|
|
|
|
self.outputs_writer = KVWriter(self.outputs_dir)
|
2022-03-01 08:01:56 +01:00
|
|
|
self.core_processor = ContractProcessor(outputs_writer=self.outputs_writer)
|
2021-10-11 12:27:51 +02:00
|
|
|
|
|
|
|
self.resources = {
|
2022-03-01 08:01:56 +01:00
|
|
|
"token": {
|
|
|
|
"reference": self.token_address,
|
|
|
|
"key_address": addresses[0],
|
|
|
|
},
|
|
|
|
"token_index": {
|
|
|
|
"reference": self.token_index_address,
|
|
|
|
"key_address": addresses[1],
|
|
|
|
},
|
|
|
|
"address_declarator": {
|
|
|
|
"reference": self.address_declarator_address,
|
|
|
|
"key_address": addresses[2],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
proof_dir = os.path.join(test_data_dir, "proof")
|
2021-10-11 12:27:51 +02:00
|
|
|
attach = Attachment(path=proof_dir)
|
|
|
|
attach.load()
|
|
|
|
self.proofs = Proof(proof_dir, attachments=attach)
|
|
|
|
self.proofs.load()
|