def test_tx(with_block_height=1, signers: List[types.UInt160] = None) -> payloads.Transaction: if signers is None: new_signers = [ payloads.Signer( types.UInt160.from_string( "f782c7fbb2eef6afe629b96c0d53fb525eda64ce"), payloads.WitnessScope.GLOBAL) ] else: new_signers = list( map(lambda v: payloads.Signer(v, payloads.WitnessScope.GLOBAL), signers)) tx = payloads.Transaction(version=0, nonce=123, system_fee=456, network_fee=789, valid_until_block=with_block_height + 1, attributes=[], signers=new_signers, script=b'\x01', witnesses=[]) tx.block_height = with_block_height return tx
def signer_auto_checker(signer: Union[str, UInt160, Hash160Str, payloads.Signer], scope: payloads.WitnessScope) -> payloads.Signer: type_signer = type(signer) if type_signer is str and len(signer) == 40: return payloads.Signer(types.UInt160.from_string(signer), scope) elif type_signer is payloads.Signer: return signer elif type_signer is UInt160: return payloads.Signer(signer, scope) elif type_signer is Hash160Str: return payloads.Signer(signer.to_UInt160(), scope) else: raise ValueError( f'Unable to handle signer {signer} with type {type_signer}')
def test_assign_and_get_role(self): engine = test_engine(has_snapshot=True, has_container=True) # set signers list to our committee to pass check_committee() validation engine.script_container.signers = [ payloads.Signer( types.UInt160.from_string( "54166e586e86b9d653bf96f61e6568df7a8ecb50"), payloads.WitnessScope.GLOBAL) ] public_key1 = cryptography.KeyPair(b'\x01' * 32).public_key public_key2 = cryptography.KeyPair(b'\x02' * 32).public_key public_key3 = cryptography.KeyPair(b'\x03' * 32).public_key c = contracts.DesignationContract() c.designate_as_role(engine, contracts.DesignateRole.STATE_VALIDATOR, [public_key1, public_key2]) c.designate_as_role(engine, contracts.DesignateRole.ORACLE, [public_key3]) index = engine.snapshot.persisting_block.index + 1 state_nodes = c.get_designated_by_role( engine.snapshot, contracts.DesignateRole.STATE_VALIDATOR, index) self.assertEqual(2, len(state_nodes)) self.assertIn(public_key1, state_nodes) self.assertIn(public_key2, state_nodes) oracle_nodes = c.get_designated_by_role(engine.snapshot, contracts.DesignateRole.ORACLE, index) self.assertEqual(1, len(oracle_nodes)) self.assertEqual(public_key3, oracle_nodes[0])
def add_as_sender(self, tx: payloads.Transaction): """ Add the account as sender of the transaction. Args: tx: the transaction to modify """ tx.signers.insert( 0, payloads.Signer(self.script_hash, payloads.WitnessScope.GLOBAL))
def test_tx(with_block_height=1) -> payloads.Transaction: tx = payloads.Transaction( version=0, nonce=123, system_fee=456, network_fee=789, valid_until_block=1, attributes=[], signers=[ payloads.Signer( types.UInt160.from_string( "f782c7fbb2eef6afe629b96c0d53fb525eda64ce")) ], script=b'\x01', witnesses=[]) tx.block_height = with_block_height return tx
def test_ripemd160_null(self): """ var tx = new Neo.Network.P2P.Payloads.Transaction { Version = 0, Nonce = 0, SystemFee = 0, NetworkFee = 0, ValidUntilBlock = 99999, Attributes = new TransactionAttribute[0], Script = new byte[0], Signers = new Signer[] { new Signer { Account = UInt160.Zero, Scopes = WitnessScope.FeeOnly}} }; using var script = new ScriptBuilder(); script.EmitSysCall(ApplicationEngine.Neo_Crypto_RIPEMD160); // Syscall var engine = ApplicationEngine.Create(TriggerType.Application, tx, null, 100_000_000, false); engine.LoadScript(script.ToArray()); engine.Push(StackItem.Null); Assert.AreEqual(engine.Execute(), VMState.HALT); Assert.AreEqual(1, engine.ResultStack.Count); var item = engine.ResultStack.Pop<ByteString>(); Console.WriteLine($"{item.GetSpan().ToHexString()}"); """ # we have to set the network magic number, because that is serialized as part of the "get_hash_data()" call settings.network.magic = 0x4F454E sb = vm.ScriptBuilder() sb.emit_syscall(syscall_name_to_int("Neo.Crypto.RIPEMD160")) engine = test_engine(has_container=True) engine.script_container.signers = [ payloads.Signer(types.UInt160.zero()) ] script = vm.Script(sb.to_array()) engine.load_script(script) engine.push(vm.NullStackItem()) engine.execute() self.assertEqual(vm.VMState.HALT, engine.state) self.assertEqual(1, len(engine.result_stack)) # captured from C# expected = '0892b2402eb78d878a4c60fc799d879b672a5aa5' self.assertEqual(expected, str(engine.result_stack.pop()))
def _create_genesis_block() -> payloads.Block: script = vm.ScriptBuilder().emit_syscall( contracts.syscall_name_to_int("Neo.Native.Deploy")).to_array() b = payloads.Block( version=0, prev_hash=types.UInt256.zero(), timestamp=int( datetime(2016, 7, 15, 15, 8, 21, 0, timezone.utc).timestamp() * 1000), index=0, next_consensus=Blockchain.get_consensus_address( settings.standby_validators), witness=payloads.Witness( invocation_script=b'', verification_script=b'\x11' # (OpCode.PUSH1) ), consensus_data=payloads.ConsensusData(primary_index=0, nonce=2083236893), transactions=[ payloads.Transaction( version=0, script=script, system_fee=0, network_fee=0, nonce=0, valid_until_block=0, signers=[ payloads.Signer(account=to_script_hash(b'\x11'), scope=payloads.WitnessScope.FEE_ONLY) ], witnesses=[ payloads.Witness(invocation_script=b'', verification_script=b'\x11') ]) ]) return b