def test_enforce_interface_fails_on_wrong_funcs(self): interface = [ imports.Func('transfer', args=('amount', 'to')), imports.Func('balance_of', args=('account', )), imports.Func('spooky'), imports.Func('allowance', args=('owner', 'spender')), imports.Func('transfer_from', args=('amount', 'to', 'main_account')) ] self.assertFalse(imports.enforce_interface(self.module, interface))
def test_enforce_interface_works_on_subset_funcs(self): interface = [ imports.Func('transfer', args=('amount', 'to')), imports.Func('balance_of', args=('account', )), imports.Func('total_supply'), imports.Func('allowance', args=('owner', 'spender')), imports.Func('transfer_from', args=('amount', 'to', 'main_account')) ] self.assertTrue(imports.enforce_interface(self.module, interface))
def test_func_false_private(self): def __sup(a, b): return a + b s = imports.Func(name='sup', args=('x', 'y'), private=True) self.assertFalse(s.is_of(__sup))
def test_func_correct_private(self): def __sup(a, b): return a + b s = imports.Func(name='sup', args=('a', 'b'), private=True) self.assertTrue(s.is_of(__sup))
def test_func_correct_with_kwargs_and_annotations(self): def sup(x: int = 100, y: int = 100): return x + y s = imports.Func(name='sup', args=('x', 'y')) self.assertTrue(s.is_of(sup))
def test_func_correct_with_kwargs(self): def sup(x=100, y=200): return x + y s = imports.Func(name='sup', args=('x', 'y')) self.assertTrue(s.is_of(sup))
def test_func_incorrect_args(self): def sup(a, b): return a + b s = imports.Func(name='sup', args=('x', 'y')) self.assertFalse(s.is_of(sup))
def test_func_incorrect_name(self): def sup(x, y): return x + y s = imports.Func(name='not_much', args=('x', 'y')) self.assertFalse(s.is_of(sup))
def test_func_correct_type(self): def sup(x, y): return x + y s = imports.Func(name='sup', args=('x', 'y')) self.assertTrue(s.is_of(sup))
def test_complete_enforcement_with_private_func(self): interface = [ imports.Func('transfer', args=('amount', 'to')), imports.Func('balance_of', args=('account', )), imports.Func('total_supply'), imports.Func('allowance', args=('owner', 'spender')), imports.Func('approve', args=('amount', 'to')), imports.Func('private_func', private=True), imports.Func('transfer_from', args=('amount', 'to', 'main_account')), imports.Var('supply', Variable), imports.Var('balances', Hash) ] self.assertTrue(imports.enforce_interface(self.module, interface))
def test_private_function_enforcement(self): interface = [ imports.Func('private_func', private=True), ] self.assertTrue(imports.enforce_interface(self.module, interface))