def test_call_value_and_data(msig, mock, usrs): action = Action(CallType.CALL, mock.address, C.ZERO_ADDRESS, 3000, 1, '0xabababab') tx_value = 10 tx = signAndExecute(msig, usrs, action, {'value': tx_value}) call = tx.events[-1] assert msig.nonce() == 1 assert call['src'] == msig.address assert call['context'] == action.target assert call['gas'] <= action.gas + 2300 assert call['val'] == action.value assert call['data'] == action.data assert msig.balance() == tx_value - action.value
def test_dcal_value_and_data(msig, mock, usrs): value = 100 action = Action(CallType.DELEGATECALL, mock.address, C.ZERO_ADDRESS, 4000, value, '0xdeadbeef') tx = signAndExecute(msig, usrs, action, {'value': value}) call = utils.last_call_log(tx.logs, mock.abi) assert msig.balance() == value assert msig.nonce() == 1 assert call['src'] == tx.sender assert checksum(call['context']) == msig.address assert call['gas'] <= action.gas assert call['val'] == action.value assert call['data'] == action.data
def test_fail_short_signature(msig, usrs, anyone): action = Action(CallType.CALL) nonce = msig.nonce() digest = utils.encode_digest(msig, nonce, action) lst_sigs = [ bytes(u.signHash(digest).signature).hex() for u in usrs ] lst_sigs[1] = lst_sigs[1][:-1] sigs = ''.join(lst_sigs) with brownie.reverts(): msig.execute( action.source, action.target, action.type, action.gas, action.value, action.data, sigs )
def test_fail_unordered_sigs(msig, usrs): bad_usrs = usrs.copy() bad_usrs[0], bad_usrs[1] = bad_usrs[1], bad_usrs[0] action = Action(CallType.CALL) nonce = msig.nonce() digest = utils.encode_digest(msig, nonce, action) sigs = utils.allSign(bad_usrs, digest) with brownie.reverts(): msig.execute( action.source, action.target, action.type, action.gas, action.value, action.data, sigs )
def test_last_threshold_signers(deployer, usrs, usr_ids): threshold = len(usrs) - 1 action = Action(CallType.CALL) (msig, _) = utils.new_msig(deployer, threshold, usr_ids) signAndExecute(msig, usrs[-threshold:], action) assert msig.nonce() == 1
def test_repeat_signer(msig, usrs): signers = usrs.copy() signers.insert(1, signers[0]) action = Action(CallType.CALL) with brownie.reverts(): signAndExecute(msig, signers, action)
def test_two_calls(msig, usrs): signAndExecute(msig, usrs, Action(CallType.CALL)) signAndExecute(msig, usrs, Action(CallType.CALL)) assert msig.nonce() == 2
def test_fail_bad_signer(msig, usrs, any_signers): bad_usrs = usrs.copy() bad_usrs[C.THRESHOLD - 1] = any_signers[0] with brownie.reverts(): signAndExecute(msig, bad_usrs, Action(CallType.CALL))
def test_fail_insufficient_sigs(msig, usrs): action = Action(CallType.CALL) with brownie.reverts(): signAndExecute(msig, usrs[0:C.THRESHOLD - 1], action)
def test_fail_wrong_source(msig, deployer, anyone, usrs): action = Action(CallType.CALL, C.ZERO_ADDRESS, deployer.address) with brownie.reverts(): signAndExecute(msig, usrs, action, {'from': anyone})
def test_with_source(msig, deployer, usrs): action = Action(CallType.CALL, C.ZERO_ADDRESS, deployer.address) signAndExecute(msig, usrs, action, {'from': deployer})
def test_fail_bad_calltype(msig, usrs): with brownie.reverts(): signAndExecute(msig, usrs, Action(CallType.INVALID))
def test_fail_short_calldata(msig, usrs, anyone): action = Action(CallType.CALL) cdata = utils.signAndEncodeCalldata(msig, usrs, action) with brownie.reverts(): anyone.transfer(msig.address, data=cdata[:-1])
def test_dcall_empty_target(msig, usrs): action = Action(CallType.DELEGATECALL, C.ADDRESS_EMPTY, C.ZERO_ADDRESS, 3000, 0, '0xdeadbeefab') signAndExecute(msig, usrs, action) assert msig.nonce() == 1
async def update(state: AppState, action: Action) -> Eff[[ACTIONS, EFFECTS], AppState]: new_state = None o_changed_box = None if type(action) == LinkSelectionAction: old_link_selection = state.link_selection link_selection = update_link_selection(old_link_selection, state.graph, action) if link_selection.src_slot != None and link_selection.dst_slot != None: link = (link_selection.src_slot, link_selection.dst_slot) can_create_link = ng.is_input_slot_free(state.graph, link[1]) link_already_exists = link in state.graph.links if link_already_exists: await emit(ng.GraphAction.Disconnect(*link)) elif can_create_link: await emit(ng.GraphAction.Connect(*link)) else: # link is invalid - e.g. connects to a filled slot # but we empty it after anyway, so do nothing pass link_selection = LinkSelection.empty new_state = state.set('link_selection', link_selection) elif type(action) == ng.GraphAction: graph = state.graph new_state = state.set('graph', await ng.update_graph(graph, action)) elif type(action) == SourceAction: debug_log('updating', 'source') target_id = action.id_ old_source_box_state = state.source_boxes[target_id] new_source_box_state = update_source(old_source_box_state, action) # might emit effects if not (old_source_box_state is new_source_box_state): source_boxes = state['source_boxes'] new_state = state.set( 'source_boxes', source_boxes.set(target_id, new_source_box_state)) o_changed_box = target_id elif type(action) in FILTER_BOX_ACTION_TYPES: debug_log('updating', 'filter box') target_id = action.id_ old_filter_box_state = state.filter_boxes[target_id] new_filter_box_state = update_filter_box(old_filter_box_state, action) if not (old_filter_box_state is new_filter_box_state): filter_boxes = state['filter_boxes'] new_state = state.set( 'filter_boxes', filter_boxes.set(target_id, new_filter_box_state)) o_changed_box = target_id elif type(action) in PLOT_BOX_ACTION_TYPES: # state_e['plots'][target_id] = update_plot(plot_state, state_e['data'], __plot_draw_area__, action) debug_log('updating', 'plot') target_id = action.id_ plots = state['plots'] old_plot_state = plots[target_id] new_plot_state = update_plot_box(old_plot_state, action) # signal_data = state.data.box_outputs # new_plot_state = await update_plot_box(old_plot_state, signal_data, action) if not (old_plot_state is new_plot_state): # reference comparison for speed new_state = state.set('plots', plots.set(target_id, new_plot_state)) # o_changed_box = target_id elif type(action) == FileAction: if action.is_Load(): await emit_effect(FileEffect.Load(action.filename)) elif type(action) == AppStateAction: await emit_effect({ AppStateAction.ResetState: AppStateEffect.ResetState, AppStateAction.SaveState: AppStateEffect.SaveState, AppStateAction.LoadState: AppStateEffect.LoadState, AppStateAction.ResetUserActionHistory: AppStateEffect.ResetUserActionHistory, AppStateAction.SaveUserActionHistory: AppStateEffect.SaveUserActionHistory, AppStateAction.LoadUserActionHistory: AppStateEffect.LoadUserActionHistory, AppStateAction.RunHistory: AppStateEffect.RunHistory, }[action]) elif type(action) == AppRunnerAction: await emit_effect({ AppRunnerAction.Reload(): AppRunnerEffect.Reload(), AppRunnerAction.Exit(): AppRunnerEffect.Exit(), }[action]) else: util.impossible('Unknown action of type {}: {}'.format( type(action), action)) if o_changed_box != None: # await emit(ng.NodeChanged(id_=o_changed_box)) await emit_effect(ng.GraphEffect.EvalGraph()) return (new_state if new_state is not None else state) \ .transform(['n_actions'], lambda x: x+1)