Refer to this guide to understand how the Key-Value contract works, in addition to some detail on how the Casperlabs Contract DSL works.
Follow this link to execute this contract in an online IDE.
To test the contract, run: make test
This will build the contract, copy the wasm target to make it available for the tests and then run the test suite.