mirror of
https://github.com/logos-blockchain/logos-blockchain-specs.git
synced 2026-01-09 08:33:09 +00:00
74 lines
1.9 KiB
Python
74 lines
1.9 KiB
Python
from unittest import TestCase
|
|
from dataclasses import dataclass
|
|
|
|
from crypto import Field, prf
|
|
from note import InnerNote, PublicNote, SecretNote, nf_pk
|
|
from partial_transaction import PartialTransaction, InputNote, OutputNote
|
|
from transaction_bundle import TransactionBundle
|
|
|
|
from constraints import Vacuous
|
|
|
|
|
|
class TestTransfer(TestCase):
|
|
def test_1_to_1_transfer(self):
|
|
# Alice wants to transfer ownership of a note to Bob.
|
|
|
|
@dataclass
|
|
class User:
|
|
sk: Field
|
|
|
|
@property
|
|
def pk(self) -> Field:
|
|
return nf_pk(self.sk)
|
|
|
|
alice = User(sk=Field.random())
|
|
bob = User(sk=Field.random())
|
|
|
|
alices_note = SecretNote(
|
|
note=InnerNote(
|
|
value=100,
|
|
unit="NMO",
|
|
birth_constraint=Vacuous(),
|
|
death_constraints=[Vacuous()],
|
|
state=Field.zero(),
|
|
nonce=Field.random(),
|
|
rand=Field.random(),
|
|
),
|
|
nf_sk=alice.sk,
|
|
)
|
|
|
|
tx_rand = Field.random()
|
|
bobs_note = PublicNote(
|
|
note=InnerNote(
|
|
value=100,
|
|
unit="NMO",
|
|
birth_constraint=Vacuous(),
|
|
death_constraints=[Vacuous()],
|
|
state=Field.zero(),
|
|
nonce=Field.random(),
|
|
rand=Field.random(),
|
|
),
|
|
nf_pk=bob.pk,
|
|
)
|
|
|
|
ptx = PartialTransaction(
|
|
inputs=[
|
|
InputNote(
|
|
note=alices_note,
|
|
death_cm=Vacuous().hash(),
|
|
death_proof=Vacuous().prove(),
|
|
)
|
|
],
|
|
outputs=[
|
|
OutputNote(
|
|
note=bobs_note,
|
|
birth_proof=Vacuous().prove(),
|
|
)
|
|
],
|
|
rand=tx_rand,
|
|
)
|
|
|
|
bundle = TransactionBundle(bundle=[ptx])
|
|
|
|
assert bundle.verify()
|