1
1
mirror of https://github.com/anoma/juvix.git synced 2024-09-20 13:07:20 +03:00

[test] Add Anoma Haskell backend for VP

This commit is contained in:
Paul Cadman 2022-04-08 16:45:19 +01:00 committed by Jan Mas Rovira
parent d023ced9e4
commit 721ea4612d
2 changed files with 74 additions and 7 deletions

View File

@ -0,0 +1,16 @@
module Anoma where
import Prelude
readPre :: String -> Int
readPre "change1-key" = 100
readPre "change2-key" = 90
readPre _ = -1
readPost :: String -> Int
readPost "change1-key" = 90
readPost "change2-key" = 100
readPost _ = -1
isBalanceKey :: String -> String -> String
isBalanceKey _ _ = "owner-address"

View File

@ -210,21 +210,19 @@ unwrap-default o ≔ maybe-int 0 o;
change-from-key : String → Int;
change-from-key key ≔ unwrap-default (read-post key) - unwrap-default (read-pre key);
check-vp : ListString → String → String → Int → PairIntBool;
check-vp verifiers key owner change ≔
check-vp : ListString → String → Int → String → PairIntBool;
check-vp verifiers key change owner
if-pairIntBool
(change-from-key key < 0)
-- make sure the spender approved the transaction
(MakePair (change + (change-from-key key)) (elem owner verifiers))
(MakePair (change + (change-from-key key)) true);
check-vp' : ListString → String → Int → String → PairIntBool;
check-vp' verifiers key change owner ≔ check-vp verifiers key owner change;
check-keys : String → ListString → PairIntBool → String → PairIntBool;
check-keys token verifiers (MakePair change is-success) key ≔
if-pairIntBool
is-success
(pair-from-optionString (check-vp' verifiers key change) (is-balance-key token key))
(pair-from-optionString (check-vp verifiers key change) (is-balance-key token key))
(MakePair 0 false);
check-result : PairIntBool → Bool;
@ -235,6 +233,59 @@ vp token keys-changed verifiers ≔
check-result
(foldl
(check-keys token verifiers)
(MakePair 0 false) keys-changed);
(MakePair 0 true)
keys-changed);
--------------------------------------------------------------------------------
-- IO
--------------------------------------------------------------------------------
axiom Action : Type {
ghc ↦ "IO ()";
};
axiom putStr : String → Action {
ghc ↦ "putStr";
};
axiom putStrLn : String → Action {
ghc ↦ "putStrLn";
};
infixl 1 >>;
axiom >> : Action → Action → Action {
ghc ↦ "(>>)";
};
show-result : Bool → String;
show-result true ≔ "OK";
show-result false ≔ "FAIL";
--------------------------------------------------------------------------------
-- Testing VP
--------------------------------------------------------------------------------
token : String;
token ≔ "owner-token";
owner-address : String;
owner-address ≔ "owner-address";
change1-key : String;
change1-key ≔ "change1-key";
change2-key : String;
change2-key ≔ "change2-key";
verifiers : ListString;
verifiers ≔ Cons owner-address Nil;
keys-changed : ListString;
keys-changed ≔ Cons change1-key (Cons change2-key Nil);
main : Action;
main ≔
(putStr "VP Status: ")
>> (putStrLn (show-result (vp token keys-changed verifiers)));
end;