diff --git a/src/contracts/HashStore.h b/src/contracts/HashStore.h new file mode 100644 index 000000000..98c2d044d --- /dev/null +++ b/src/contracts/HashStore.h @@ -0,0 +1,39 @@ +// src/contracts/HashStore.h + +struct HASHSTORE { + Array hash; +}; + +// Input/output para o procedimento de setar o hash +struct SetHash_input { + Array hash; +}; +struct SetHash_output {}; + +// Input/output para a função de consultar o hash +struct GetHash_input {}; +struct GetHash_output { + Array hash; +}; + +// Procedimento público para setar o hash +PUBLIC_PROCEDURE(SetHash) +{ + for (uint32 i = 0; i < 32; i += 1) { + state.hash[i] = input.hash[i]; + } +} + +// Função pública para consultar o hash +PUBLIC_FUNCTION(GetHash) +{ + for (uint32 i = 0; i < 32; i += 1) { + output.hash[i] = state.hash[i]; + } +} + +// Registro das interfaces +void REGISTER_USER_FUNCTIONS_AND_PROCEDURES() { + REGISTER_USER_PROCEDURE(SetHash, 1); + REGISTER_USER_FUNCTION(GetHash, 2); +} \ No newline at end of file diff --git a/test/contract_hashstore.cpp b/test/contract_hashstore.cpp new file mode 100644 index 000000000..de4057635 --- /dev/null +++ b/test/contract_hashstore.cpp @@ -0,0 +1,30 @@ +#include "gtest/gtest.h" +#include "contracts/HashStore.h" + +TEST(HashStore, SetAndGetHash) +{ + // Instancia o estado do contrato + HASHSTORE state = {}; + + // Cria um hash de teste + SetHash_input setInput = {}; + for (uint32_t i = 0; i < 32; ++i) + setInput.hash[i] = static_cast(i); + + SetHash_output setOutput = {}; + + // Chama o procedimento para setar o hash + // Simula o contexto do QPI (pode ser vazio para teste simples) + QpiContextProcedureCall qpi_proc; + SetHash(state, setInput, setOutput, qpi_proc); + + // Consulta o hash salvo + GetHash_input getInput = {}; + GetHash_output getOutput = {}; + QpiContextFunctionCall qpi_func; + GetHash(state, getInput, getOutput, qpi_func); + + // Verifica se o hash retornado é igual ao que foi setado + for (uint32_t i = 0; i < 32; ++i) + EXPECT_EQ(getOutput.hash[i], setInput.hash[i]); +} \ No newline at end of file