def test_envelope(self): """ You can read/write on the envelope of objects. """ world = World(MagicMock()) obj = MagicMock() env = world.envelope(obj) self.assertTrue(isinstance(env, dict)) env['foo'] = 'bar'
def test_execute_workRequired_succeed(self): """ If work is required, succeed if the solution is good. """ e = self.friendlyEngine() e.engine.workRequirement.return_value = Work(0, 'bar') world = World(MagicMock()) action = MagicMock() world.envelope(action)['work_solution'] = 'anything will work' yield e.execute(world, action) action.execute.assert_called_once_with(world)
def test_envelope_ids(self): """ You can read/write on the envelope of things in the world (using their id). """ world = World(MagicMock()) obj_id = world.create('foo')['id'] env = world.envelope(obj_id) self.assertTrue(isinstance(env, dict)) env['foo'] = 'bar' # destruction should destroy the envelope too world.destroy(obj_id) self.assertRaises(KeyError, world.envelope, obj_id)
def test_execute_workRequired_fail(self): """ If work is required, fail if there's not a satisfactory solution provided on the action's envelope. """ e = self.friendlyEngine() # require some work e.engine.workRequirement.return_value = Work(int('f'*40, 16), 'nonce') # fail to do an action since no work is provided. world = World(MagicMock()) action = MagicMock() self.assertFailure(e.execute(world, action), InvalidSolution) # fail to do the action since the work provided is wrong. world.envelope(action)['work_solution'] = 'hey' self.assertFailure(e.execute(world, action), InvalidSolution)
def test_execute_workRequired_fail(self): """ If work is required, fail if there's not a satisfactory solution provided on the action's envelope. """ e = self.friendlyEngine() # require some work e.engine.workRequirement.return_value = Work(int('f' * 40, 16), 'nonce') # fail to do an action since no work is provided. world = World(MagicMock()) action = MagicMock() self.assertFailure(e.execute(world, action), InvalidSolution) # fail to do the action since the work provided is wrong. world.envelope(action)['work_solution'] = 'hey' self.assertFailure(e.execute(world, action), InvalidSolution)