コード例 #1
0
    def test_balance_of(self):
        engine = test_engine(has_snapshot=True)
        block = test_block(0)
        # set or we won't pass the native deploy call
        engine.snapshot.persisting_block = block

        engine.invoke_syscall_by_name("Neo.Native.Deploy")

        gas = contracts.GasToken()
        neo = contracts.NeoToken()

        deploy_expected_gas = 30_000_000
        deploy_expected_neo = 100_000_000
        self.assertEqual(
            deploy_expected_gas,
            gas.balance_of(engine.snapshot, self.validator_account) /
            gas.factor)
        self.assertEqual(
            deploy_expected_neo,
            neo.balance_of(engine.snapshot, self.validator_account))

        self.assertEqual(vm.BigInteger.zero(),
                         gas.balance_of(engine.snapshot, types.UInt160.zero()))
        self.assertEqual(vm.BigInteger.zero(),
                         neo.balance_of(engine.snapshot, types.UInt160.zero()))
コード例 #2
0
 def get_script_hashes_for_verifying(
         self, snapshot: storage.Snapshot) -> List[types.UInt160]:
     validators = contracts.NeoToken().get_next_block_validators(snapshot)
     if len(validators) < self.validator_index:
         raise ValueError("Validator index is out of range")
     return [
         to_script_hash(
             contracts.Contract.create_signature_redeemscript(
                 validators[self.validator_index]))
     ]
コード例 #3
0
    def verify(self, snapshot: storage.Snapshot, tx: Transaction) -> bool:
        """
        Verifies the attribute with the transaction

        Returns:
            True if verification passes. False otherwise.
        """
        committee = contracts.NeoToken().get_committee_address(snapshot)
        for signer in tx.signers:
            if signer.account == committee:
                return True
        return False
コード例 #4
0
    def init(self):
        self._methods: Dict[int, _NativeMethodMeta] = {}  # offset, meta

        self._management = contracts.ManagementContract()
        self._neo = contracts.NeoToken()
        self._gas = contracts.GasToken()
        self._policy = contracts.PolicyContract()
        self._oracle = contracts.OracleContract()
        self._ledger = contracts.LedgerContract()
        self._role = contracts.DesignationContract()
        self._crypto = contracts.CryptoContract()
        self._stdlib = contracts.StdLibContract()

        # Find all methods that have been augmented by the @register decorator
        # and turn them into methods that can be called by VM scripts
        methods_meta = []
        for pair in inspect.getmembers(self,
                                       lambda m: hasattr(m, "native_call")):
            methods_meta.append(_NativeMethodMeta(pair[1]))

        methods_meta.sort(
            key=lambda x: (x.descriptor.name, len(x.descriptor.parameters)))

        sb = vm.ScriptBuilder()
        for meta in methods_meta:
            meta.descriptor.offset = len(sb)
            sb.emit_push(0)
            self._methods.update({len(sb): meta})
            sb.emit_syscall(1736177434)  # "System.Contract.CallNative"
            sb.emit(vm.OpCode.RET)

        self._script: bytes = sb.to_array()
        self.nef = contracts.NEF("neo-core-v3.0", self._script)

        sender = types.UInt160.zero()  # OpCode.PUSH1
        sb = vm.ScriptBuilder()
        sb.emit(vm.OpCode.ABORT)
        sb.emit_push(sender.to_array())
        sb.emit_push(0)
        sb.emit_push(self.service_name())
        self._hash: types.UInt160 = to_script_hash(sb.to_array())
        self._manifest: contracts.ContractManifest = contracts.ContractManifest(
        )
        self._manifest.name = self.service_name()
        self._manifest.abi.methods = list(
            map(lambda m: m.descriptor, methods_meta))

        if self._id != NativeContract._id:
            self._contracts.update({self.service_name(): self})
            self._contract_hashes.update({self._hash: self})

        self.active_block_index = settings.native_contract_activation.get(
            self.service_name, 0)
コード例 #5
0
    def test_total_supply(self):
        engine = test_engine(has_snapshot=True)
        block = test_block(0)
        # set or we won't pass the native deploy call
        engine.snapshot.persisting_block = block

        engine.invoke_syscall_by_name("Neo.Native.Deploy")
        gas = contracts.GasToken()
        neo = contracts.NeoToken()
        self.assertEqual(30_000_000 * gas.factor,
                         gas.total_supply(engine.snapshot))
        self.assertEqual(100_000_000, neo.total_supply(engine.snapshot))
コード例 #6
0
    def test_total_supply(self):
        engine = test_engine(has_snapshot=True)
        block = test_block(0)
        # set or we won't pass the native deploy call
        engine.snapshot.persisting_block = block

        gas = contracts.GasToken()
        neo = contracts.NeoToken()
        # this is now the initial stored value + the result of the post_persist event (=committee reward added)
        expected_total_gas_supply = vm.BigInteger(3000000050000000)
        self.assertEqual(expected_total_gas_supply,
                         gas.total_supply(engine.snapshot))
        self.assertEqual(100_000_000, neo.total_supply(engine.snapshot))
コード例 #7
0
ファイル: blockchain.py プロジェクト: simplitech/neo-mamba
    def init(self,
             backend: storage.IDBImplementation = None,
             store_genesis_block=True):  # type: ignore
        self.backend = backend if backend else settings.database
        self._current_snapshot = None
        self.genesis_block = self._create_genesis_block()
        self.genesis_block.rebuild_merkle_root()

        sb = vm.ScriptBuilder()
        for c in [contracts.GasToken(), contracts.NeoToken()]:
            sb.emit_contract_call(c.script_hash, "onPersist")  # type: ignore
            sb.emit(vm.OpCode.DROP)
        self.native_onpersist_script = sb.to_array()

        if self.currentSnapshot.block_height < 0 and store_genesis_block:
            self.persist(self.genesis_block)
コード例 #8
0
ファイル: transaction.py プロジェクト: DanPopa46/neo-mamba
 def verify(self, snapshot: storage.Snapshot, tx: Transaction) -> bool:
     committee = contracts.NeoToken().get_committee_address(snapshot)
     for signer in tx.signers:
         if signer.account == committee:
             return True
     return False
コード例 #9
0
 def _check_committee(self, engine: contracts.ApplicationEngine) -> bool:
     addr = contracts.NeoToken().get_committee_address(engine.snapshot)
     return engine.checkwitness(addr)
コード例 #10
0
ファイル: test_native.py プロジェクト: DanPopa46/neo-mamba
 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)
コード例 #11
0
#            "type": "Integer"
#          },
#          {
#            "name": "data",
#            "type": "Any"
#          }
#        ],
#        "returntype": "Boolean",

# Source account converted to byte array to match the ABI interface
from_account = account.script_hash.to_array()
# Destination account converted to byte array to match the ABI interface
to_account = wallet.Account.address_to_script_hash(
    "NU5unwNcWLqPM21cNCRP1LPuhxsTpYvNTf").to_array()
# We multiply this amount with the contract factor (to adjust for tokens with decimals)
amount = 10_000_000 * contracts.NeoToken().factor
# Arbitrary additional data to supply that will be printed in the "transfer" notify event.
data = None

sb = vm.ScriptBuilder()
sb.emit_dynamic_call_with_args(contracts.NeoToken().hash, "transfer",
                               [from_account, to_account, amount, data])

# With our script done we need to create a Transaction and add the script to it.
tx = payloads.Transaction(
    version=0,
    nonce=123,
    system_fee=0,
    network_fee=0,
    valid_until_block=
    1500,  # Make sure this is higher than the current chain height!
コード例 #12
0
 def test_token_symbols(self):
     gas_symbol = contracts.GasToken().symbol()
     neo_symbol = contracts.NeoToken().symbol()
     self.assertEqual("gas", gas_symbol)
     self.assertEqual("neo", neo_symbol)
コード例 #13
0
 def test_token_standards(self):
     gas_standards = contracts.GasToken().supported_standards()
     neo_standards = contracts.NeoToken().supported_standards()
     self.assertEqual(["NEP-5"], gas_standards)
     self.assertEqual(["NEP-5"], neo_standards)