The test environment doesn't have OpenResty libraries, so we need to provide mock implementations for testing. Created: - tests/mock_resty_sha256.lua: Uses system sha256sum command to compute SHA-256 hashes. Mimics the resty.sha256 API (new, update, final). - tests/mock_resty_string.lua: Implements to_hex() to convert binary strings to hexadecimal. Updated test.lua to preload these mocks so that when the module or tests require 'resty.sha256' or 'resty.string', they get our mock implementations instead. This allows the PoW verification tests to run and actually verify the SHA-256 proof-of-work.
13 lines
267 B
Lua
13 lines
267 B
Lua
-- Mock implementation of resty.string for testing
|
|
|
|
local str = {}
|
|
|
|
function str.to_hex(binary)
|
|
local hex = {}
|
|
for i = 1, #binary do
|
|
table.insert(hex, string.format("%02x", string.byte(binary, i)))
|
|
end
|
|
return table.concat(hex)
|
|
end
|
|
|
|
return str
|