Skip to content

Commit

Permalink
Prevent assertion error on send_operations with errors
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-François <[email protected]>
  • Loading branch information
bilboquet committed Nov 28, 2023
1 parent 4965daa commit f97f937
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions massa_test_framework/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
from urllib.parse import urlparse

from typing import List, Dict, Optional, Callable
from typing import List, Dict, Optional, Callable, Union

import betterproto
from grpclib.client import Channel
Expand Down Expand Up @@ -36,6 +36,7 @@
import requests
import tomlkit


class Node:
def __init__(self, server: Server, compile_unit: CompileUnit):
"""Init a Node (e.g. a Massa Node) object
Expand Down Expand Up @@ -280,7 +281,6 @@ def edit_config(self):
# print("is fp closed:", fp.closed)
# print("end of edit_config")


@contextmanager
def edit_json(self, json_filepath: Path, mode: str = "r+", default_json=None):
fp = self.server.open(json_filepath, mode)
Expand Down Expand Up @@ -376,17 +376,27 @@ def add_staking_secret_keys(self, secret_keys: List[str]) -> None:
res = self.priv_api2.add_staking_secret_keys(secret_keys)
return res

def send_operations(self, operations: List[bytes]) -> List[str]:
def send_operations(
self, operations: List[bytes]
) -> Union[List[str], Dict[str, str]]:
"""Send operations (like coin transfer)
Send serialized operations using jsonrpc api
Args:
operations: a list of serialized operations
Returns:
a list of operation id
on success: a list of operation id
on error: a dict with key "error" and value the error message
"""
res = self.pub_api2.send_operations(operations)

# check if there is an error
err = res.get("error", None)
if err is not None:
msg = str(err.get("message", "Unknown error"))
return {"error": msg}

return res["result"]

def node_peers_whitelist(self):
Expand Down

0 comments on commit f97f937

Please sign in to comment.