debugging create()

This commit is contained in:
Jarrad Hope 2015-07-13 21:05:52 +02:00
parent 320d75ec71
commit 3dfd381017
5 changed files with 63 additions and 103 deletions

View File

@ -6,7 +6,7 @@
extern xorll.se: [insert:[int256,int256,int256,int256]:int256, np:[int256]:int256, test:[]:_, traverse:[int256]:_] extern xorll.se: [insert:[int256,int256,int256,int256]:int256, np:[int256]:int256, test:[]:_, traverse:[int256]:_]
trade_offers = create('xorll.se') monkey = create('xorll.se')
preferences = create('xorll.se') preferences = create('xorll.se')
# maybe instead of state, have different linked lists for each stage? # maybe instead of state, have different linked lists for each stage?

44
contracts/test.py Normal file
View File

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
from ethereum import tester, slogging
import os
state = tester.state()
def listener(msg):
if msg['event'] == 'LOG':
print(msg['topics'])
slogging.log_listeners.listeners.append(listener)
# print(serpent.compile('contracts/market.se'))
# os.chdir('contracts/')
# with open('market.se') as fh:
# market_se = fh.read()
# market = state.abi_contract(market_se)
test_contract = state.abi_contract('test.se')
print('success')
market = state.abi_contract('market.se')
# ticket = market.add()
# print(ticket)
# ticket2 = market.add()
# print(ticket)
# head = tail = xorll.insert("head", 10, 0, 0)
# tail = xorll.insert("tail", 20, 0, tail)
# tail = xorll.insert("monkey", 30, xorll.np(tail), tail)
# tail = xorll.insert("finger", 40, xorll.np(tail), tail)
# print('---')
# xorll.traverse(head)
# print('---')
# xorll.traverse(tail)
# print('---')
# xorll.test()

4
contracts/test.se Normal file
View File

@ -0,0 +1,4 @@
extern xorll.se: [insert:[int256,int256,int256,int256]:int256, np:[int256]:int256, test:[]:_, traverse:[int256]:_]
monkey = create('xorll.se')
preferences = create('xorll.se')

21
test.py
View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from ethereum import tester, slogging from ethereum import tester, slogging
import os
state = tester.state() state = tester.state()
@ -11,16 +12,22 @@ def listener(msg):
slogging.log_listeners.listeners.append(listener) slogging.log_listeners.listeners.append(listener)
with open('contracts/market.se') as fh:
market_se = fh.read() # print(serpent.compile('contracts/market.se'))
# os.chdir('contracts/')
# with open('market.se') as fh:
# market_se = fh.read()
# market = state.abi_contract(market_se)
market = state.abi_contract('contracts/market.se')
market = state.abi_contract(market_se)
ticket = market.add() # ticket = market.add()
print(ticket) # print(ticket)
ticket2 = market.add() # ticket2 = market.add()
print(ticket) # print(ticket)
# head = tail = xorll.insert("head", 10, 0, 0) # head = tail = xorll.insert("head", 10, 0, 0)
# tail = xorll.insert("tail", 20, 0, tail) # tail = xorll.insert("tail", 20, 0, tail)

View File

@ -1,95 +0,0 @@
from ethereum import tester, utils
import os
class TestHeapContract(object):
CONTRACT = 'contracts/minheap.se'
CONTRACT_GAS = 325169
def setup_class(cls):
cls.s = tester.state()
cls.c = cls.s.abi_contract(cls.CONTRACT)
cls.snapshot = cls.s.snapshot()
def setup_method(self, method):
self.s.revert(self.snapshot)
def test_create_gas_used(self):
print("create gas used:", self.s.block.gas_used)
assert self.s.block.gas_used <= self.CONTRACT_GAS
def test_init(self):
assert self.s.block.get_code(self.c.address) != ''
assert utils.int_to_addr(self.s.block.get_storage_data(self.c.address, 0)) == tester.a0
assert self.c.size() == 0
assert self.c.top() == 0
def test_pop_empty_heap(self):
assert self.c.pop() == 0
assert self.c.size() == 0
assert self.c.top() == 0
assert self.c.pop() == 0
assert self.c.size() == 0
assert self.c.top() == 0
def test_only_owner_can_modify(self):
self.c.push(1, sender=tester.k1)
assert self.c.size() == 0
assert self.c.top() == 0
self.c.push(1)
assert self.c.pop(sender=tester.k1) is None
assert self.c.size() == 1
assert self.c.top() == 1
def test_push_1_pop_1(self):
self.c.push(1)
assert self.c.size() == 1
assert self.c.top() == 1
assert self.c.pop() == 1
assert self.c.size() == 0
assert self.c.top() == 0
def test_push_1_2_pop_1_2(self):
self.c.push(1)
assert self.c.size() == 1
assert self.c.top() == 1
self.c.push(2)
assert self.c.size() == 2
assert self.c.top() == 1
assert self.c.pop() == 1
assert self.c.size() == 1
assert self.c.top() == 2
assert self.c.pop() == 2
assert self.c.size() == 0
assert self.c.top() == 0
def test_push_3_1_2_pop_1_2_3(self):
self.c.push(3)
assert self.c.size() == 1
assert self.c.top() == 3
self.c.push(1)
assert self.c.size() == 2
assert self.c.top() == 1
self.c.push(2)
assert self.c.size() == 3
assert self.c.top() == 1
assert self.c.pop() == 1
assert self.c.size() == 2
assert self.c.top() == 2
assert self.c.pop() == 2
assert self.c.size() == 1
assert self.c.top() == 3
assert self.c.pop() == 3
assert self.c.size() == 0
assert self.c.top() == 0