Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/contract_qswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ContractTestingQswap : protected ContractTesting

bool loadState(const CHAR16* filename)
{
return load(filename, sizeof(QSWAP), contractStates[QSWAP_CONTRACT_INDEX]) == sizeof(QSWAP);
return loadContractState(QSWAP_CONTRACT_INDEX, filename);
}

QSWAP::InvestRewardsInfo_output investRewardsInfo()
Expand Down
2 changes: 1 addition & 1 deletion test/contract_qx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class ContractTestingQx : protected ContractTesting

bool loadState(const CHAR16* filename)
{
return load(filename, sizeof(QX), contractStates[QX_CONTRACT_INDEX]) == sizeof(QX);
return loadContractState(QX_CONTRACT_INDEX, filename);
}

// TODO: add other functions
Expand Down
18 changes: 18 additions & 0 deletions test/contract_testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ class ContractTesting : public LoggingTest
}
}

// Load a contract state file, which must match the current state size exactly.
bool loadContractState(unsigned int contractIndex, const CHAR16* filename)
{
const unsigned long long stateSize = contractDescriptions[contractIndex].stateSize;
FILE* file = nullptr;
if (_wfopen_s(&file, (const wchar_t*)filename, L"rb") != 0 || !file)
return false;
_fseeki64(file, 0, SEEK_END);
const long long fileSize = _ftelli64(file);
fclose(file);
if (fileSize < 0 || (unsigned long long)fileSize != stateSize)
{
std::cout << "State file has " << fileSize << " bytes, expected " << stateSize << std::endl;
return false;
}
return load(filename, stateSize, contractStates[contractIndex]) == stateSize;
}

void initEmptySpectrum()
{
initSpectrum();
Expand Down
Loading