Remove unused tests

This commit is contained in:
radrow 2022-05-08 10:53:35 +02:00
parent 369804a334
commit c0718589c8
28 changed files with 0 additions and 646 deletions

View File

@ -1,15 +0,0 @@
## Requires ocaml >= 4.02, < 4.06
## and reason-3.0.0 (opam install reason).
default : voting_test
%.ml : %.re
refmt -p ml $< > $@
voting_test : rte.ml voting.ml voting_test.ml
ocamlopt -o $@ $^
clean :
rm -f *.cmi *.cmx *.ml *.o voting_test

View File

@ -1,31 +0,0 @@
// A simple test of the abort built-in function.
contract AbortTest =
record state = { value : int }
public function init(v : int) =
{ value = v }
// Aborting
public function do_abort(v : int, s : string) : unit =
put_value(v)
revert_abort(s)
// Accessing the value
public function get_value() = state.value
public function put_value(v : int) = put(state{value = v})
public function get_values() : list(int) = [state.value]
public function put_values(v : int) = put(state{value = v})
// Some basic statistics
public function get_stats(acct : address) =
( Contract.balance, Chain.balance(acct) )
// Abort functions.
private function revert_abort(s : string) =
abort(s)
// This is still legal but will be stripped out.
// TODO: This function confuses the type inference, so it cannot be present.
//private function abort(s : string) = 42

View File

@ -1,27 +0,0 @@
contract Interface =
function do_abort : (int, string) => unit
function get_value : () => int
function put_value : (int) => unit
function get_values : () => list(int)
function put_values : (int) => unit
contract AbortTestInt =
record state = {r : Interface, value : int}
public function init(r : Interface, value : int) =
{r = r, value = value}
// Aborting
public function do_abort(v : int, s : string) =
put_value(v)
state.r.do_abort(v + 100, s)
// Accessing the value
public function put_value(v : int) = put(state{value = v})
public function get_value() = state.value
public function get_values() : list(int) =
state.value :: state.r.get_values()
public function put_values(v : int) =
put_value(v)
state.r.put_values(v + 1000)

View File

@ -1,8 +0,0 @@
contract ChannelEnv =
public function coinbase() : address = Chain.coinbase
public function timestamp() : int = Chain.timestamp
public function block_height() : int = Chain.block_height
public function difficulty() : int = Chain.difficulty

View File

@ -1,7 +0,0 @@
contract ChannelOnChainContractNameResolution =
public function can_resolve(name: string, key: string) : bool =
switch(AENS.resolve(name, key) : option(string))
None => false
Some(_address) => true

View File

@ -1,51 +0,0 @@
contract ChannelOnChainContractOracle =
type query_t = string
type answer_t = string
type oracle_id = oracle(query_t, answer_t)
type query_id = oracle_query(query_t, answer_t)
record state = { oracle : oracle_id,
question : string,
bets : map(string, address)
}
public function init(oracle: oracle_id, question: string) : state =
{ oracle = oracle,
question = question,
bets = {}
}
public stateful function place_bet(answer: string) =
switch(Map.lookup(answer, state.bets))
None =>
put(state{ bets = state.bets{[answer] = Call.caller}})
"ok"
Some(_value) =>
"bet_already_taken"
public function expiry() =
Oracle.expiry(state.oracle)
public function query_fee() =
Oracle.query_fee(state.oracle)
public function get_question(q: query_id) =
Oracle.get_question(state.oracle, q)
public stateful function resolve(q: query_id) =
switch(Oracle.get_answer(state.oracle, q))
None =>
"no response"
Some(result) =>
if(state.question == Oracle.get_question(state.oracle, q))
switch(Map.lookup(result, state.bets))
None =>
"no winning bet"
Some(winner) =>
Chain.spend(winner, Contract.balance)
"ok"
else
"different question"

View File

@ -1,9 +0,0 @@
contract Remote =
function get : () => int
function can_resolve : (string, string) => bool
contract RemoteCall =
function remote_resolve(r : Remote, name: string, key: string) : bool =
r.can_resolve(name, key)

View File

@ -1,51 +0,0 @@
contract Chess =
type board = map(int, map(int, string))
type state = board
private function get_row(r, m : board) =
Map.lookup_default(r, m, {})
private function set_piece(r, c, p, m : board) =
m { [r] = get_row(r, m) { [c] = p } }
private function get_piece(r, c, m : board) =
Map.lookup(c, get_row(r, m))
private function from_list(xs, m : board) =
switch(xs)
[] => m
(r, c, p) :: xs => from_list(xs, set_piece(r, c, p, m))
function init() =
from_list([ (2, 1, "white pawn"), (7, 1, "black pawn")
, (2, 2, "white pawn"), (7, 2, "black pawn")
, (2, 3, "white pawn"), (7, 3, "black pawn")
, (2, 4, "white pawn"), (7, 4, "black pawn")
, (2, 5, "white pawn"), (7, 5, "black pawn")
, (2, 6, "white pawn"), (7, 6, "black pawn")
, (2, 7, "white pawn"), (7, 7, "black pawn")
, (2, 8, "white pawn"), (7, 8, "black pawn")
, (1, 1, "white rook"), (8, 1, "black rook")
, (1, 2, "white knight"), (8, 2, "black knight")
, (1, 3, "white bishop"), (8, 3, "black bishop")
, (1, 4, "white queen"), (8, 4, "black queen")
, (1, 5, "white king"), (8, 5, "black king")
, (1, 6, "white bishop"), (8, 6, "black bishop")
, (1, 7, "white knight"), (8, 7, "black knight")
, (1, 8, "white rook"), (8, 8, "black rook")
], {})
function piece(r, c) = get_piece(r, c, state)
function move_piece(r, c, r1, c1) =
switch(piece(r, c))
Some(p) => put(set_piece(r1, c1, p, state))
function destroy_piece(r, c) =
put(state{ [r] = Map.delete(c, get_row(r, state)) })
function delete_row(r) =
put(Map.delete(r, state))

View File

@ -1,20 +0,0 @@
contract OtherContract =
function multiply : (int, int) => int
contract ThisContract =
record state = { server : OtherContract, n : int }
function init(server : OtherContract) =
{ server = server, n = 2 }
function square() =
put(state{ n @ n = state.server.multiply(value = 100, n, n) })
function get_n() = state.n
function tip_server() =
Chain.spend(state.server.address, Call.value)

View File

@ -1,87 +0,0 @@
contract ERC20Token =
record state = {
totalSupply : int,
decimals : int,
name : string,
symbol : string,
balances : map(address, int),
allowed : map(address, map(address,int)),
// Logs, remove when native Events are there
transfer_log : list((address,address,int)),
approval_log : list((address,address,int))}
// init(100000000, 10, "Token Name", "TKN")
public stateful function init(_totalSupply : int, _decimals : int, _name : string, _symbol : string ) = {
totalSupply = _totalSupply,
decimals = _decimals,
name = _name,
symbol = _symbol,
balances = {[Call.caller] = _totalSupply }, // creator gets all Tokens
allowed = {},
// Logs, remove when native Events are there
transfer_log = [],
approval_log = []}
public stateful function totalSupply() : int = state.totalSupply
public stateful function decimals() : int = state.decimals
public stateful function name() : string = state.name
public stateful function symbol() : string = state.symbol
public stateful function balanceOf(tokenOwner : address ) : int =
Map.lookup_default(tokenOwner, state.balances, 0)
public stateful function transfer(to : address, tokens : int) =
put( state{balances[Call.caller] = sub(state.balances[Call.caller], tokens) })
put( state{balances[to] = add(Map.lookup_default(to, state.balances, 0), tokens) })
transferEvent(Call.caller, to, tokens)
true
public stateful function approve(spender : address, tokens : int) =
// allowed[Call.caller] field must have a value!
ensure_allowed(Call.caller)
put( state{allowed[Call.caller][spender] = tokens} )
approvalEvent(Call.caller, spender, tokens)
true
public stateful function transferFrom(from : address, to : address, tokens : int) =
put( state{ balances[from] = sub(state.balances[from], tokens) })
put( state{ allowed[from][Call.caller] = sub(state.allowed[from][Call.caller], tokens) })
put( state{ balances[to] = add(balanceOf(to), tokens) })
transferEvent(from, to, tokens)
true
public function allowance(_owner : address, _spender : address) : int =
state.allowed[_owner][_spender]
public stateful function getTransferLog() : list((address,address,int)) =
state.transfer_log
public stateful function getApprovalLog() : list((address,address,int)) =
state.approval_log
//
// Private Functions
//
private function ensure_allowed(key : address) =
switch(Map.lookup(key, state.allowed))
None => put(state{allowed[key] = {}})
Some(_) => ()
private function transferEvent(from : address, to : address, tokens : int) =
let e = (from, to, tokens)
put( state{transfer_log = e :: state.transfer_log })
e
private function approvalEvent(from : address, to : address, tokens : int) =
let e = (from, to, tokens)
put( state{approval_log = e :: state.approval_log })
e
private function sub(_a : int, _b : int) : int =
require(_b =< _a, "Error")
_a - _b
private function add(_a : int, _b : int) : int =
let c : int = _a + _b
require(c >= _a, "Error")
c

View File

@ -1,6 +0,0 @@
contract Exploits =
// We'll hack the bytecode of this changing the return type to string.
function pair(n : int) = (n, 0)

View File

@ -1,9 +0,0 @@
contract Remote =
function missing : (int) => int
contract Init_error =
record state = {value : int}
function init(r : Remote, x : int) =
{value = r.missing(x)}

View File

@ -1,7 +0,0 @@
contract Fail =
entrypoint tttt() : bool * int =
let f(x : 'a) : 'a = x
(f(true), f(1))

View File

@ -1,36 +0,0 @@
contract MapOfMaps =
type board = map(int, map(int, string))
type map2('a, 'b, 'c) = map('a, map('b, 'c))
record state = { big1 : map2(string, string, string),
big2 : map2(string, string, string),
small1 : map(string, string),
small2 : map(string, string) }
private function empty_state() =
{ big1 = {}, big2 = {},
small1 = {}, small2 = {} }
function init() = empty_state()
function setup_state() =
let small = {["key"] = "val"}
put({ big1 = {["one"] = small},
big2 = {["two"] = small},
small1 = small,
small2 = small })
// -- Garbage collection of inner map when outer map is garbage collected
function test1_setup() =
let inner = {["key"] = "val"}
put(empty_state() { big1 = {["one"] = inner} })
function test1_execute() =
put(state{ big1 = {} })
function test1_check() =
state.big1

View File

@ -1,29 +0,0 @@
contract MapUpdater =
function update_map : (int, string, map(int, string)) => map(int, string)
contract Benchmark =
record state = { updater : MapUpdater,
map : map(int, string) }
function init(u, m) = { updater = u, map = m }
function set_updater(u) = put(state{ updater = u })
function update_map(k : int, v : string, m) = m{ [k] = v }
function update(a : int, b : int, v : string) =
if (a > b) ()
else
put(state{ map[a] = v })
update(a + 1, b, v)
function get(k) = state.map[k]
function noop() = ()
function benchmark(k, v) =
let m = state.updater.update_map(k, v, state.map)
put(state{ map = m })
m

View File

@ -1,6 +0,0 @@
contract MinimalInit =
record state = {foo : int}
function init() =
{ foo = 0 }

View File

@ -1,7 +0,0 @@
contract MultiplicationServer =
function multiply(x : int, y : int) =
switch(Call.value >= 100)
true => x * y

View File

@ -1,11 +0,0 @@
contract OraclesErr =
public function unsafeCreateQueryThenErr(
o : oracle(string, int),
q : string,
qfee : int,
qttl : Chain.ttl,
rttl : Chain.ttl) : oracle_query(string, int) =
let x = Oracle.query(o, q, qfee, qttl, rttl)
switch(0) 1 => ()
x // Never reached.

View File

@ -1,22 +0,0 @@
contract OraclesGas =
type fee = int
type question_t = string
type answer_t = int
public function happyPathWithAllBuiltinsAtSameHeight(
qfee : fee,
ottl : Chain.ttl,
ettl : Chain.ttl,
qttl : Chain.ttl,
rttl : Chain.ttl
) =
let question = "why"
let answer = 42
let o = Oracle.register(Contract.address, qfee, ottl) : oracle(question_t, answer_t)
Oracle.extend(o, ettl)
require(qfee =< Call.value, "insufficient value for qfee")
let q = Oracle.query(o, question, qfee, qttl, rttl)
Oracle.respond(o, q, answer)
()

View File

@ -1,35 +0,0 @@
contract Oracles =
type fee = int
type ttl = Chain.ttl
type query_t = string
type answer_t = string
type oracle_id = oracle(query_t, answer_t)
type query_id = oracle_query(query_t, answer_t)
function createQuery(o : oracle_id,
q : query_t,
qfee : fee,
qttl : ttl,
rttl : ttl) : query_id =
require(qfee =< Call.value, "insufficient value for qfee")
Oracle.query(o, q, qfee, qttl, rttl)
function respond(o : oracle_id,
q : query_id,
sign : signature,
r : answer_t) : unit =
Oracle.respond(o, q, signature = sign, r)
function getQuestion(o : oracle_id,
q : query_id) : query_t =
Oracle.get_question(o, q)
function getAnswer(o : oracle_id,
q : query_id) : option(answer_t) =
Oracle.get_answer(o, q)

View File

@ -1,16 +0,0 @@
contract Identity =
function zip_with(f, xs, ys) =
switch((xs, ys))
(x :: xs, y :: ys) => f(x, y) :: zip_with(f, xs, ys)
_ => []
// Check that we can use zip_with at different types
function foo() =
zip_with((x, y) => x + y, [1, 2, 3], [4, 5, 6, 7])
function bar() =
zip_with((x, y) => if(x) y else 0, [true, false, true, false], [1, 2, 3])

View File

@ -1,57 +0,0 @@
contract MapServer =
function insert : (string, string, map(string, string)) => map(string, string)
function delete : (string, map(string, string)) => map(string, string)
contract PrimitiveMaps =
record state = { remote : MapServer,
map : map(string, string),
map2 : map(string, string) }
function init(r) =
let m = {}
{ remote = r, map = m, map2 = m }
function set_remote(r) = put(state{ remote = r })
function insert(k, v, m) : map(string, string) = m{ [k] = v }
function delete(k, m) : map(string, string) = Map.delete(k, m)
function remote_insert(k, v, m) =
state.remote.insert(k, v, m)
function remote_delete(k, m) =
state.remote.delete(k, m)
function get_state_map() = state.map
function set_state_map(m) = put(state{ map = m })
function clone_state() = put(state{ map2 = state.map })
function insert_state(k, v) = put(state{ map @ m = m { [k] = v } })
function delete_state(k) = put(state{ map @ m = Map.delete(k, m) })
function lookup_state(k) = Map.lookup(k, state.map)
function double_insert_state(k, v1, v2) =
put(state{ map @ m = m { [k] = v1 },
map2 @ m = m { [k] = v2 } })
function test() =
let m = {} : map(string, string)
let m1 = m { ["foo"] = "value_of_foo",
["bla"] = "value_of_bla" }
let m2 = Map.delete("foo", m1)
let m3 = m2 { ["bla"] = "new_value_of_bla" }
[Map.lookup("foo", m), Map.lookup("bla", m),
Map.lookup("foo", m1), Map.lookup("bla", m1),
Map.lookup("foo", m2), Map.lookup("bla", m2),
Map.lookup("foo", m3), Map.lookup("bla", m3)]
function return_map() =
Map.delete("goo", {["foo"] = "bar", ["goo"] = "gaa"})
function argument_map(m : map(string, string)) =
m["foo"]

View File

@ -1,20 +0,0 @@
contract Remote1 =
function set : (int) => int
contract RemoteCall =
record state = { i : int }
function init(x) = { i = x }
function set( x : int) : int =
let old = state.i
put(state{ i = x })
old
function call(r : Remote1, x : int, g : int) : int =
r.set(gas = g, value = 10, x)
function get() = state.i

View File

@ -1,23 +0,0 @@
contract RemoteState =
record rstate = { i : int, s : string, m : map(int, int) }
function look_at(s : rstate) = ()
function return_s(big : bool) =
let x = "short"
let y = "______longer_string_at_least_32_bytes_long___________longer_string_at_least_32_bytes_long___________longer_string_at_least_32_bytes_long_____"
if(big) y else x
function return_m(big : bool) =
let x = { [1] = 2 }
let y = { [1] = 2, [3] = 4, [5] = 6 }
if(big) y else x
function get(s : rstate) = s
function get_i(s : rstate) = s.i
function get_s(s : rstate) = s.s
function get_m(s : rstate) = s.m
function fun_update_i(s : rstate, ni) = s{ i = ni }
function fun_update_s(s : rstate, ns) = s{ s = ns }
function fun_update_m(s : rstate, nm) = s{ m = nm }
function fun_update_mk(s : rstate, k, v) = s{ m = s.m{[k] = v} }

View File

@ -1,22 +0,0 @@
contract Remote =
function id : ('a) => 'a
function missing : ('a) => 'a
function wrong_type : (string) => string
contract Main =
function id(x : int) =
x
function wrong_type(x : int) =
x
function remote_id(r : Remote, x) =
r.id(x)
function remote_missing(r : Remote, x) =
r.missing(x)
function remote_wrong_type(r : Remote, x) =
r.wrong_type(x)

View File

@ -1,21 +0,0 @@
contract ValueOnErr =
function err : () => int
function ok : () => int
contract RemoteValueOnErr =
public function callErr(
r : ValueOnErr,
value : int) : int =
r.err(value = value)
public function callErrLimitGas(
r : ValueOnErr,
value : int,
gas : int) : int =
r.err(value = value, gas = gas)
public function callOk(
r : ValueOnErr,
value : int) : int =
r.ok(value = value)

View File

@ -1,6 +0,0 @@
contract UpfrontCharges =
record state = { b : int } // For enabling retrieval of sender balance observed inside init.
public function init() : state = { b = b() }
public function initialSenderBalance() : int = state.b
public function senderBalance() : int = b()
private function b() = Chain.balance(Call.origin)

View File

@ -1,7 +0,0 @@
contract ValueOnErr =
public function err() : int =
switch(0) 1 => 5
public function ok() : int =
11