Add is_account/1 and account_pubkey/1 helpers
Gajumaru Serialization Tests / tests (push) Successful in 11s
Gajumaru Serialization Tests / tests (push) Successful in 11s
Extended-auth account ids use an {account, Subtype} tag. These helpers
let callers test account membership and extract the 32-byte pubkey
without pattern-matching on specialize/1 results.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
-module(gmser_id_tests).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(PUBKEY, <<12345:32/unit:8>>).
|
||||
|
||||
is_account_test() ->
|
||||
{"is_account recognizes standard and extended account ids",
|
||||
fun() ->
|
||||
?assert(gmser_id:is_account(gmser_id:create(account, ?PUBKEY))),
|
||||
?assert(gmser_id:is_account(gmser_id:create({account, 0}, ?PUBKEY))),
|
||||
?assert(gmser_id:is_account(gmser_id:create({account, 5}, ?PUBKEY))),
|
||||
?assertNot(gmser_id:is_account(gmser_id:create(contract, ?PUBKEY))),
|
||||
?assertNot(gmser_id:is_account(not_an_id))
|
||||
end}.
|
||||
|
||||
account_pubkey_test() ->
|
||||
{"account_pubkey returns the 32-byte account hash",
|
||||
fun() ->
|
||||
?assertEqual(?PUBKEY,
|
||||
gmser_id:account_pubkey(gmser_id:create(account, ?PUBKEY))),
|
||||
?assertEqual(?PUBKEY,
|
||||
gmser_id:account_pubkey(gmser_id:create({account, 3}, ?PUBKEY))),
|
||||
?assertEqual(?PUBKEY,
|
||||
gmser_id:account_pubkey(gmser_id:create({account, 6}, ?PUBKEY)))
|
||||
end}.
|
||||
|
||||
account_pubkey_matches_specialize_test() ->
|
||||
{"account_pubkey agrees with specialize/2 for account ids",
|
||||
fun() ->
|
||||
Id = gmser_id:create({account, 2}, ?PUBKEY),
|
||||
?assertEqual(gmser_id:specialize(Id, account),
|
||||
gmser_id:account_pubkey(Id))
|
||||
end}.
|
||||
|
||||
extended_account_roundtrip_test() ->
|
||||
{"extended account ids round-trip through encode/decode",
|
||||
fun() ->
|
||||
Id = gmser_id:create({account, 4}, ?PUBKEY),
|
||||
?assert(gmser_id:is_account(Id)),
|
||||
Id1 = gmser_id:decode(gmser_id:encode(Id)),
|
||||
?assertEqual(?PUBKEY, gmser_id:account_pubkey(Id1)),
|
||||
?assertEqual(account, gmser_id:specialize_type(Id1))
|
||||
end}.
|
||||
Reference in New Issue
Block a user