Skip to content

Commit

Permalink
ERC20 transfer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed Jan 5, 2024
1 parent ce4cbc4 commit 5956b4b
Show file tree
Hide file tree
Showing 29 changed files with 453 additions and 4 deletions.
64 changes: 64 additions & 0 deletions tests/expected_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ std::vector<std::string> FormatAddress(uint32_t prefix, const std::string &name,
return answer;
}

std::vector<std::string> FormatEthAddress(const uint32_t idx, const std::string &name, const std::string &address) {
auto answer = std::vector<std::string>();
uint8_t numPages = 0;
char outBuffer[100];

pageString(outBuffer, fieldSize, address.c_str(), 0, &numPages);

for (auto i = 0; i < numPages; i++) {
MEMZERO(outBuffer, sizeof(outBuffer));
pageString(outBuffer, fieldSize, address.c_str(), i, &numPages);

auto pages = std::string("");

if (numPages > 1) {
pages = fmt::format("[{}/{}] ", i + 1, numPages);
}

addTo(answer, "{} | {}{}: {}", idx, name, pages, outBuffer);
}

return answer;
}

std::string FormatAmount(const std::string &amount) {
char buffer[500];
MEMZERO(buffer, sizeof(buffer));
Expand Down Expand Up @@ -205,3 +228,44 @@ std::vector<std::string> ClientDealGenerateExpectedUIOutput(const Json::Value &j

return answer;
}

std::vector<std::string> EVMGenerateExpectedUIOutput(const Json::Value &json, bool) {
auto answer = std::vector<std::string>();

bool valid = true;
if (json.isMember("value")) {
valid = json["valid"].asBool();
}

if (!valid) {
answer.emplace_back("Test case is not valid!");
return answer;
}

///
auto message = json["message"];
auto to = message["To"].asString();
auto value = message["Value"].asString();
auto nonce = message["Nonce"].asString();
auto gasPrice = message["GasPrice"].asString();
auto gasLimit = message["GasLimit"].asString();
///

uint8_t idx = 0;
auto destAddress = FormatEthAddress(idx, "To", to);
answer.insert(answer.end(), destAddress.begin(), destAddress.end());

idx++;
addTo(answer, "{} | Value: {}", idx, value);

idx++;
addTo(answer, "{} | Nonce: {}", idx, nonce);

idx++;
addTo(answer, "{} | Gas price: {}", idx, gasPrice);

idx++;
addTo(answer, "{} | Gas limit: {}", idx, gasLimit);

return answer;
}
1 change: 1 addition & 0 deletions tests/expected_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@

std::vector<std::string> GenerateExpectedUIOutput(const Json::Value &json, bool expertMode);
std::vector<std::string> ClientDealGenerateExpectedUIOutput(const Json::Value &json, bool expertMode);
std::vector<std::string> EVMGenerateExpectedUIOutput(const Json::Value &json, bool expertMode);
Loading

0 comments on commit 5956b4b

Please sign in to comment.