Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_time(self):
logger.info(crypto.now())
def test_stateless_validator_true(self):
logger.debug("test_create_account")
create_ac = Command.CreateAccount(
account_name = "rihito",
domain_id = "light.wing",
main_pubkey = self.keypair.public_key
)
payload = Transaction.Payload(
commands = [
Command(create_account = create_ac)
],
creator_account_id = self.creator,
tx_counter = self.tx_counter,
created_time = crypto.now()
)
tx = Transaction(
payload = payload,
signatures = [
Signature(
pubkey = self.keypair.public_key,
signature = crypto.sign(self.keypair,crypto.sign_hash(payload))
)
]
)
self.assertTrue(stateless_validator.verify(tx))
def test_stateless_get_transactions(self):
create_ac = Command.CreateAccount(
account_name = "rihito",
domain_id = "light.wing",
main_pubkey = self.keypair.public_key
)
payload = Transaction.Payload(
commands = [
Command(create_account = create_ac)
],
creator_account_id = self.creator,
tx_counter = self.tx_counter,
created_time = crypto.now()-3600*24*1000*10
)
get_txs = GetTransactions(
tx_hashes = [
crypto.sign_hash(payload)
]
)
self.assertTrue(stateless_validator.get_transactions(get_txs))
get_txs = GetTransactions(
tx_hashes = [
b"aaaaa0000000"
]
)
self.assertFalse(stateless_validator.get_transactions(get_txs))
def test_stateless_validator_created_at_ng(self):
logger.debug("test_stateless_validator_created_at_ng")
create_ac = Command.CreateAccount(
account_name = "rihito",
domain_id = "light.wing",
main_pubkey = self.keypair.public_key
)
payload = Transaction.Payload(
commands = [
Command(create_account = create_ac)
],
creator_account_id = self.creator,
tx_counter = self.tx_counter,
created_time = crypto.now()-3600*24*1000*10
)
tx = Transaction(
payload = payload,
signatures = [
Signature(
pubkey = self.keypair.public_key,
signature = crypto.sign(self.keypair,crypto.sign_hash(payload))
)
]
)
self.assertFalse(stateless_validator.verify(tx))
payload = Transaction.Payload(
commands = [
Command(create_account = create_ac)
def setUp(self):
self.keypair = crypto.create_key_pair()
create_ac = Command.CreateAccount(
account_name = "rihito",
domain_id = "light.wing",
main_pubkey = self.keypair.public_key
)
self.payload = Transaction.Payload(
commands = [
Command(create_account = create_ac)
],
creator_account_id = "rihito@light.wing",
tx_counter = 0,
created_time = crypto.now()
)
self.tx = Transaction(
payload = self.payload,
signatures = [
Signature(
pubkey = self.keypair.public_key,
signature = crypto.sign(self.keypair,crypto.sign_hash(self.payload))
)
def test_stateless_validator_signature_ng(self):
logger.debug("test_stateless_validator_signature_ng")
create_ac = Command.CreateAccount(
account_name = "rihito",
domain_id = "light.wing",
main_pubkey = self.keypair.public_key
)
payload = Transaction.Payload(
commands = [
Command(create_account = create_ac)
],
creator_account_id = self.creator,
tx_counter = self.tx_counter,
created_time = crypto.now()
)
payload2 = Transaction.Payload(
commands = [
Command(create_account = create_ac)
],
creator_account_id = self.creator,
tx_counter = self.tx_counter,
created_time = crypto.now()+1
)
tx = Transaction(
payload = payload,
signatures = [
Signature(
pubkey = self.keypair.public_key,
signature = crypto.sign(self.keypair,crypto.sign_hash(payload2))
)
def __init__(self):
logger.debug("Create Query Construct")
self.query = QuerySchema(
payload = QuerySchema.Payload(
created_time = crypto.now()
)
# TODO query has signature
)
self.signatories = Signatories()
def verify_created_time(time):
logger.info("Stateless Check Time")
logger.info("created time: " + str(time))
now = crypto.now()
logger.info("now time : " + str(now))
one_second = 1000
# なんか時間ずれるの5秒ほど許容する。
if now - MAX_DELAY <= time and time <= now + one_second * 5:
return True
logger.info("Stateless Out Range Time Failed")
return False
def __init__(self):
logger.debug("Create Transaction Construct")
self.tx = TransactionSchema(
payload = TransactionSchema.Payload(
created_time = crypto.now()
),
signatures = []
)
self.signatories = Signatories()