def deploy_native(engine: contracts.ApplicationEngine) -> None: if engine.snapshot.persisting_block.index != 0: raise ValueError( "Can only deploy native contracts in the genenis block") for nc in contracts.NativeContract()._contracts.values(): engine.snapshot.contracts.put( storage.ContractState(nc.script, nc.manifest)) nc._initialize(engine)
def native_on_persist(engine: contracts.ApplicationEngine) -> None: if engine.trigger != contracts.TriggerType.ON_PERSIST: raise SystemError() # NEO implicitely expects the ManagementContract to be called first *ugh* # because ManagementContract.on_persist will call _initialize() on all other native contracts # which is needed for the other contracts to work properly when their on_persist() is called sorted_contracts = sorted(contracts.NativeContract().registered_contracts, key=lambda c: c.id, reverse=True) for contract in sorted_contracts: if contract.active_block_index <= engine.snapshot.persisting_block.index: contract.on_persist(engine)
def test_native_deploy_ok(self): engine = test_engine(has_snapshot=True) block = test_block(0) engine.snapshot.persisting_block = block engine.invoke_syscall_by_name("Neo.Native.Deploy") self.assertIn("Policy", contracts.NativeContract().registered_contract_names) self.assertEqual(contracts.PolicyContract(), contracts.NativeContract.get_contract("Policy"))
def test_various(self): native = contracts.NativeContract() known_contracts = native.registered_contracts self.assertIn(contracts.GasToken(), known_contracts) self.assertIn(contracts.NeoToken(), known_contracts) self.assertIn(contracts.PolicyContract(), known_contracts)