An Elixir application which uses tendermint for replicating the state in blockchain.
Simulation of passing a ball between defined participants as a blckochain transaction.
Assumptions:
- There is an array of whitelisted participants
["a", "b", "c", "d"]
. - The initial state of the app is that participant
"a"
is holding a ball. This information is stored in the state under the key:participant_who_has_the_ball
. checkTX
block is responsible for validating transaction against a merkle proof and the current state of the blockchain.deliverTX
is responsible for updating the state of the blockchain.tx
tendermint parameter for passing the ball transaction is sent as a value of two fieldstx="from=a:to=b"
which is later parsed in the app.
- Install tendermint (instructions)
- Install elixir (recommend asdf)
- Clone this repository
git clone [email protected]:Skoda091/tendermint-state-replication-test-project.git
-
Run tendermint
tendermint init
tendermint node
-
Run elixir app
mix deps.get
iex -S mix
-
To pass the ball to a whitelisted participant, run from interactive Elixir (IEx):
iex(1)> TendermintStateReplicationTestProject.BallService.pass_ball("a", "b")
Where the first argument is the current owner of the ball and the second argument is the recipient. This fuction will create an HTTP request to tendermint.
http://localhost:46657/broadcast_tx_commit?tx="from=a:to=b"
Expected result of this function.
%{ "check_tx" => %{ "code" => 0, "data" => "", "fee" => "0", "gas" => "0", "log" => "" }, "deliver_tx" => %{"code" => 0, "data" => "", "log" => "", "tags" => []}, "hash" => "492AC2718137712A2733177090971DB28B71F23E", "height" => 4 }
Example of incorrect transaction result.
%{ "check_tx" => %{ "code" => 1, "data" => "", "fee" => "0", "gas" => "0", "log" => "Current ball owner is incorrect, a participant doesn't have the ball." }, "deliver_tx" => %{"code" => 0, "data" => "", "log" => "", "tags" => []}, "hash" => "492AC2718137712A2733177090971DB28B71F23E", "height" => 0 }
-
To check the current state of the ball run from iex:
iex(2)> TendermintStateReplicationTestProject.BallService.check_ball_owner()
Expected result of this function.
%{ "code" => 0, "decoded_key" => "participant_who_has_the_ball", "decoded_value" => "b", "height" => "0", "index" => "0", "key" => "7061727469636970616E745F77686F5F6861735F7468655F62616C6C", "log" => "", "proof" => "", "value" => "62" }
Result extended with keys
decoded_key
anddecoded_value
only for the purpose of convinience while testing.
- Add unit tests unit and integration
- Add integration tests
- Add documentation