Skip to content

Commit

Permalink
Add integration test for atomic commits
Browse files Browse the repository at this point in the history
Adds an integration test to ensure that updates either
all commit or none of them do in parsec. Specifically
ensures that a commit attempt where not all update keys
have associated tickets aborts.

Signed-off-by: Michael Maurer <[email protected]>
  • Loading branch information
maurermi authored and HalosGhost committed Jan 17, 2024
1 parent 3e2a3ef commit c3ea4df
Show file tree
Hide file tree
Showing 5 changed files with 503 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/parsec/agent/runners/lua/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef OPENCBDC_TX_SRC_PARSEC_AGENT_RUNNERS_LUA_SERVER_H_
#define OPENCBDC_TX_SRC_PARSEC_AGENT_RUNNERS_LUA_SERVER_H_

#include "agent/server_interface.hpp"
#include "parsec/agent/server_interface.hpp"
#include "util/rpc/tcp_server.hpp"

namespace cbdc::parsec::agent::rpc {
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
project(integration)

add_executable(run_integration_tests mock_system.cpp
add_executable(run_integration_tests smart_contract_atomic_commit_test.cpp
mock_system.cpp
atomizer_raft_integration_test.cpp
atomizer_end_to_end_test.cpp
gtest_evm_jsonrpc_client.cpp
Expand Down Expand Up @@ -31,6 +32,7 @@ target_link_libraries(run_integration_tests ${GTEST_LIBRARY}
coordinator
locking_shard
evm_runner
lua_runner
ticket_machine
runtime_locking_shard
runners
Expand All @@ -49,6 +51,7 @@ target_link_libraries(run_integration_tests ${GTEST_LIBRARY}
${LEVELDB_LIBRARY}
${NURAFT_LIBRARY}
${JSON_LIBRARY}
${LUA_LIBRARY}
${CURL_LIBRARY}
${MHD_LIBRARY}
${CMAKE_THREAD_LIBS_INIT})
32 changes: 32 additions & 0 deletions tests/integration/correct_state_update.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function gen_bytecode()
pay_contract = function(param)
-- take out locks on keys
hk1 = "ticketed_key_1"
hk2 = "ticketed_key_2"
hk3 = "ticketed_key_3"
hk4 = "ticketed_key_4"
coroutine.yield(hk1)
coroutine.yield(hk2)
coroutine.yield(hk3)
coroutine.yield(hk4)

updates = {}
updates[hk1] = string.pack("c4", "100")
updates[hk2] = string.pack("c4", "200")
updates[hk3] = string.pack("c4", "250")
updates[hk4] = string.pack("c4", "255")

return updates
end
c = string.dump(pay_contract, true)
tot = ""
for i = 1, string.len(c) do
hex = string.format("%x", string.byte(c, i))
if string.len(hex) < 2 then
hex = "0" .. hex
end
tot = tot .. hex
end

return tot
end
31 changes: 31 additions & 0 deletions tests/integration/data_hazard_contract.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function gen_bytecode()
pay_contract = function(param)
-- take out locks on keys
hk1 = "ticketed_key_1"
hk2 = "ticketed_key_2"
hk3 = "ticketed_key_3"
uhk = "unticketed_key" -- Intentionally don't yield this key
coroutine.yield(hk1)
coroutine.yield(hk2)
coroutine.yield(hk3)

updates = {}
updates[hk1] = string.pack("c4", "100")
updates[hk2] = string.pack("c4", "200")
updates[hk3] = string.pack("c4", "250")
updates[uhk] = string.pack("c4", "255")

return updates
end
c = string.dump(pay_contract, true)
tot = ""
for i = 1, string.len(c) do
hex = string.format("%x", string.byte(c, i))
if string.len(hex) < 2 then
hex = "0" .. hex
end
tot = tot .. hex
end

return tot
end
Loading

0 comments on commit c3ea4df

Please sign in to comment.