Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def auction_tester(t):
from vyper import compiler
t.languages['vyper'] = compiler.Compiler()
contract_code = open('contracts/auctions/simple_open_auction.v.py').read()
t.c = t.s.contract(contract_code, language='vyper', args=[t.accounts[0], FIVE_DAYS])
return t
def test_timestamp_success(good_code):
assert compiler.compile_code(good_code) is not None
def test_exponent_fail(bad_code):
with raises(TypeMismatchException):
compiler.compile_code(bad_code)
def test_send_fail(bad_code):
with raises(TypeMismatchException):
compiler.compile_code(bad_code)
def test_return_mismatch(bad_code):
with raises(StructureException):
compiler.compile_code(bad_code)
def test_varname_validity_fail(bad_code):
if isinstance(bad_code, tuple):
with raises(bad_code[1]):
compiler.compile_code(bad_code[0])
else:
with raises(EventDeclarationException):
compiler.compile_code(bad_code)
def test_as_wei_fail(bad_code):
if isinstance(bad_code, tuple):
with raises(bad_code[1]):
compiler.compile_code(bad_code[0])
else:
with raises(VariableDeclarationException):
compiler.compile_code(bad_code)
def test_undef_toplevel():
code = """
@public
def foo():
x = bar(55)
"""
with raises(StructureException) as ex:
compiler.compile(code)
assert "Not a top-level function: bar" in str(ex.value)
def test_block_fail(bad_code):
if isinstance(bad_code, tuple):
with raises(bad_code[1]):
compiler.compile_code(bad_code[0])
else:
with raises(TypeMismatchException):
compiler.compile_code(bad_code)
from sputnik.parser import Parser
from vyper import compiler
if __name__ == '__main__':
#2
# Setup Sputnik and deploy vyper contract
SputnikParser = Parser('contracts/otp.sputnik')
proggy = SputnikParser.get_program()
sputnik = Sputnik(proggy, None)
with open('contracts/hasheater.vy', 'r') as f:
contract_code = f.read()
contract_bytecode = compiler.compile(contract_code).hex()
contract_abi = compiler.mk_full_signature(contract_code)
w3.eth.defaultAccount = w3.eth.accounts[0]
Contract = w3.eth.contract(abi=contract_abi, bytecode=contract_bytecode)
tx_hash = Contract.constructor().transact()
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
contract = w3.eth.contract(
address=tx_receipt.contractAddress,
abi=contract_abi)
#3
# Setup numpy (insecure, but it's a hackathon...)
rng = numpy.random.RandomState()
#4
# Setup NuFHE
secret_key, bootstrap_key = nufhe.make_key_pair(sputnik.thr, rng, transform_type='NTT')