41-types #44
@ -1,37 +0,0 @@
|
|||||||
version: 2.1
|
|
||||||
|
|
||||||
executors:
|
|
||||||
aebuilder:
|
|
||||||
docker:
|
|
||||||
- image: aeternity/builder:bionic-otp23
|
|
||||||
user: builder
|
|
||||||
working_directory: ~/src
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
executor: aebuilder
|
|
||||||
steps:
|
|
||||||
- checkout
|
|
||||||
- restore_cache:
|
|
||||||
keys:
|
|
||||||
- dialyzer-cache-v1-{{ .Branch }}-{{ .Revision }}
|
|
||||||
- dialyzer-cache-v1-{{ .Branch }}-
|
|
||||||
- dialyzer-cache-v1-
|
|
||||||
- run:
|
|
||||||
name: Build
|
|
||||||
command: rebar3 compile
|
|
||||||
- run:
|
|
||||||
name: Static Analysis
|
|
||||||
command: rebar3 dialyzer
|
|
||||||
- run:
|
|
||||||
name: Eunit
|
|
||||||
command: rebar3 eunit
|
|
||||||
- run:
|
|
||||||
name: Common Tests
|
|
||||||
command: rebar3 ct
|
|
||||||
- save_cache:
|
|
||||||
key: dialyzer-cache-v1-{{ .Branch }}-{{ .Revision }}
|
|
||||||
paths:
|
|
||||||
- _build/default/rebar3_20.3.8_plt
|
|
||||||
- store_artifacts:
|
|
||||||
path: _build/test/logs
|
|
19
.gitea/workflows/demo.yaml
Normal file
19
.gitea/workflows/demo.yaml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
name: Gitea Actions Demo
|
||||||
|
run-name: ${{ gitea.actor }} is testing out Gitea Actions
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Explore-Gitea-Actions:
|
||||||
|
runs-on: linux_amd64
|
||||||
|
steps:
|
||||||
|
- run: echo "The job was automatically triggered by a ${{ gitea.event_name }} event."
|
||||||
|
- run: echo "This job is now running on a ${{ runner.os }} server hosted by Gitea!"
|
||||||
|
- run: echo "The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- run: echo "The ${{ gitea.repository }} repository has been cloned to the runner."
|
||||||
|
- run: echo "The workflow is now ready to test your code on the runner."
|
||||||
|
- name: List files in the repository
|
||||||
|
run: |
|
||||||
|
ls ${{ gitea.workspace }}
|
||||||
|
- run: echo "This job's status is ${{ job.status }}."
|
1
LICENSE
1
LICENSE
@ -1,5 +1,6 @@
|
|||||||
ISC License
|
ISC License
|
||||||
|
|
||||||
|
Copyright (c) 2025, QPQ AG
|
||||||
Copyright (c) 2017, aeternity developers
|
Copyright (c) 2017, aeternity developers
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
10
README.md
10
README.md
@ -1,9 +1,15 @@
|
|||||||
aeserialization
|
GM Serialization
|
||||||
=====
|
=====
|
||||||
|
|
||||||
Serialization helpers for Aeternity node.
|
Serialization helpers for the Gajumaru.
|
||||||
|
|
||||||
Build
|
Build
|
||||||
-----
|
-----
|
||||||
|
|
||||||
$ rebar3 compile
|
$ rebar3 compile
|
||||||
|
|
||||||
|
|
||||||
|
Test
|
||||||
|
----
|
||||||
|
|
||||||
|
$ rebar3 eunit
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @copyright (C) 2025, QPQ AG
|
||||||
%%% @copyright (C) 2017, Aeternity Anstalt
|
%%% @copyright (C) 2017, Aeternity Anstalt
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% API encoding for the Aeternity node.
|
%%% API encoding for the Gajumaru
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(aeser_api_encoder).
|
-module(gmser_api_encoder).
|
||||||
|
|
||||||
-export([encode/2,
|
-export([encode/2,
|
||||||
decode/1,
|
decode/1,
|
||||||
@ -52,9 +53,9 @@
|
|||||||
-define(BASE58, 1).
|
-define(BASE58, 1).
|
||||||
-define(BASE64, 2).
|
-define(BASE64, 2).
|
||||||
|
|
||||||
-spec encode(known_type(), payload() | aeser_id:id()) -> encoded().
|
-spec encode(known_type(), payload() | gmser_id:id()) -> encoded().
|
||||||
encode(id_hash, Payload) ->
|
encode(id_hash, Payload) ->
|
||||||
{IdType, Val} = aeser_id:specialize(Payload),
|
{IdType, Val} = gmser_id:specialize(Payload),
|
||||||
encode(id2type(IdType), Val);
|
encode(id2type(IdType), Val);
|
||||||
encode(Type, Payload) ->
|
encode(Type, Payload) ->
|
||||||
Pfx = type2pfx(Type),
|
Pfx = type2pfx(Type),
|
||||||
@ -90,14 +91,14 @@ type_size_check(Type, Bin) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec safe_decode(extended_type(), encoded()) -> {'ok', payload() | aeser_id:id()}
|
-spec safe_decode(extended_type(), encoded()) -> {'ok', payload() | gmser_id:id()}
|
||||||
| {'error', atom()}.
|
| {'error', atom()}.
|
||||||
safe_decode({id_hash, AllowedTypes}, Enc) ->
|
safe_decode({id_hash, AllowedTypes}, Enc) ->
|
||||||
try decode(Enc) of
|
try decode(Enc) of
|
||||||
{ActualType, Dec} ->
|
{ActualType, Dec} ->
|
||||||
case lists:member(ActualType, AllowedTypes) of
|
case lists:member(ActualType, AllowedTypes) of
|
||||||
true ->
|
true ->
|
||||||
try {ok, aeser_id:create(type2id(ActualType), Dec)}
|
try {ok, gmser_id:create(type2id(ActualType), Dec)}
|
||||||
catch error:_ -> {error, invalid_prefix}
|
catch error:_ -> {error, invalid_prefix}
|
||||||
end;
|
end;
|
||||||
false ->
|
false ->
|
@ -1,20 +1,21 @@
|
|||||||
%%% -*- erlang-indent-level:4; indent-tabs-mode: nil -*-
|
%%% -*- erlang-indent-level:4; indent-tabs-mode: nil -*-
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @copyright (C) 2025, QPQ AG
|
||||||
%%% @copyright (C) 2018, Aeternity Anstalt
|
%%% @copyright (C) 2018, Aeternity Anstalt
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% Functions for serializing chain objects to binary format.
|
%%% Functions for serializing chain objects to binary format.
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
|
||||||
-module(aeser_chain_objects).
|
-module(gmser_chain_objects).
|
||||||
|
|
||||||
-export([ serialize/4
|
-export([ serialize/4
|
||||||
, deserialize/4
|
, deserialize/4
|
||||||
, deserialize_type_and_vsn/1
|
, deserialize_type_and_vsn/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-type template() :: aeserialization:template().
|
-type template() :: gmserialization:template().
|
||||||
-type fields() :: aeserialization:fields().
|
-type fields() :: gmserialization:fields().
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
@ -22,15 +23,15 @@
|
|||||||
|
|
||||||
-spec serialize(atom(), non_neg_integer(), template(), fields()) -> binary().
|
-spec serialize(atom(), non_neg_integer(), template(), fields()) -> binary().
|
||||||
serialize(Type, Vsn, Template, Fields) ->
|
serialize(Type, Vsn, Template, Fields) ->
|
||||||
aeserialization:serialize(tag(Type), Vsn, Template, Fields).
|
gmserialization:serialize(tag(Type), Vsn, Template, Fields).
|
||||||
|
|
||||||
deserialize_type_and_vsn(Binary) ->
|
deserialize_type_and_vsn(Binary) ->
|
||||||
{Tag, Vsn, Fields} = aeserialization:deserialize_tag_and_vsn(Binary),
|
{Tag, Vsn, Fields} = gmserialization:deserialize_tag_and_vsn(Binary),
|
||||||
{rev_tag(Tag), Vsn, Fields}.
|
{rev_tag(Tag), Vsn, Fields}.
|
||||||
|
|
||||||
-spec deserialize(atom(), non_neg_integer(), template(), binary()) -> fields().
|
-spec deserialize(atom(), non_neg_integer(), template(), binary()) -> fields().
|
||||||
deserialize(Type, Vsn, Template, Binary) ->
|
deserialize(Type, Vsn, Template, Binary) ->
|
||||||
aeserialization:deserialize(Type, tag(Type), Vsn, Template, Binary).
|
gmserialization:deserialize(Type, tag(Type), Vsn, Template, Binary).
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
@ -1,12 +1,13 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @copyright (C) 2025, QPQ AG
|
||||||
%%% @copyright (C) 2019, Aeternity Anstalt
|
%%% @copyright (C) 2019, Aeternity Anstalt
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% Serialization of contract code
|
%%% Serialization of contract code
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(aeser_contract_code).
|
-module(gmser_contract_code).
|
||||||
|
|
||||||
-include("aeser_contract_code.hrl").
|
-include("gmser_contract_code.hrl").
|
||||||
|
|
||||||
-export([ deserialize/1
|
-export([ deserialize/1
|
||||||
, serialize/1
|
, serialize/1
|
||||||
@ -42,20 +43,20 @@ serialize(CodeMap = #{ byte_code := ByteCode
|
|||||||
|| SophiaContractVersion > ?SOPHIA_CONTRACT_VSN_1 ] ++
|
|| SophiaContractVersion > ?SOPHIA_CONTRACT_VSN_1 ] ++
|
||||||
[ {payable, Payable}
|
[ {payable, Payable}
|
||||||
|| SophiaContractVersion > ?SOPHIA_CONTRACT_VSN_2 ],
|
|| SophiaContractVersion > ?SOPHIA_CONTRACT_VSN_2 ],
|
||||||
aeser_chain_objects:serialize(compiler_sophia,
|
gmser_chain_objects:serialize(compiler_sophia,
|
||||||
SophiaContractVersion,
|
SophiaContractVersion,
|
||||||
serialization_template(SophiaContractVersion),
|
serialization_template(SophiaContractVersion),
|
||||||
Fields).
|
Fields).
|
||||||
|
|
||||||
-spec deserialize(binary()) -> map().
|
-spec deserialize(binary()) -> map().
|
||||||
deserialize(Binary) ->
|
deserialize(Binary) ->
|
||||||
case aeser_chain_objects:deserialize_type_and_vsn(Binary) of
|
case gmser_chain_objects:deserialize_type_and_vsn(Binary) of
|
||||||
{compiler_sophia = Type, ?SOPHIA_CONTRACT_VSN_1 = Vsn, _Rest} ->
|
{compiler_sophia = Type, ?SOPHIA_CONTRACT_VSN_1 = Vsn, _Rest} ->
|
||||||
Template = serialization_template(Vsn),
|
Template = serialization_template(Vsn),
|
||||||
[ {source_hash, Hash}
|
[ {source_hash, Hash}
|
||||||
, {type_info, TypeInfo}
|
, {type_info, TypeInfo}
|
||||||
, {byte_code, ByteCode}
|
, {byte_code, ByteCode}
|
||||||
] = aeser_chain_objects:deserialize(Type, Vsn, Template, Binary),
|
] = gmser_chain_objects:deserialize(Type, Vsn, Template, Binary),
|
||||||
#{ source_hash => Hash
|
#{ source_hash => Hash
|
||||||
, type_info => TypeInfo
|
, type_info => TypeInfo
|
||||||
, byte_code => ByteCode
|
, byte_code => ByteCode
|
||||||
@ -68,7 +69,7 @@ deserialize(Binary) ->
|
|||||||
, {type_info, TypeInfo}
|
, {type_info, TypeInfo}
|
||||||
, {byte_code, ByteCode}
|
, {byte_code, ByteCode}
|
||||||
, {compiler_version, CompilerVersion}
|
, {compiler_version, CompilerVersion}
|
||||||
] = aeser_chain_objects:deserialize(Type, Vsn, Template, Binary),
|
] = gmser_chain_objects:deserialize(Type, Vsn, Template, Binary),
|
||||||
#{ source_hash => Hash
|
#{ source_hash => Hash
|
||||||
, type_info => TypeInfo
|
, type_info => TypeInfo
|
||||||
, byte_code => ByteCode
|
, byte_code => ByteCode
|
||||||
@ -83,7 +84,7 @@ deserialize(Binary) ->
|
|||||||
, {byte_code, ByteCode}
|
, {byte_code, ByteCode}
|
||||||
, {compiler_version, CompilerVersion}
|
, {compiler_version, CompilerVersion}
|
||||||
, {payable, Payable}
|
, {payable, Payable}
|
||||||
] = aeser_chain_objects:deserialize(Type, Vsn, Template, Binary),
|
] = gmser_chain_objects:deserialize(Type, Vsn, Template, Binary),
|
||||||
#{ source_hash => Hash
|
#{ source_hash => Hash
|
||||||
, type_info => TypeInfo
|
, type_info => TypeInfo
|
||||||
, byte_code => ByteCode
|
, byte_code => ByteCode
|
@ -1,10 +1,11 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @copyright (C) 2025, QPQ AG
|
||||||
%%% @copyright (C) 2023, Aeternity Anstalt
|
%%% @copyright (C) 2023, Aeternity Anstalt
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% Serialization of delegation signatures
|
%%% Serialization of delegation signatures
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(aeser_delegation).
|
-module(gmser_delegation).
|
||||||
|
|
||||||
-export([ aens_preclaim_sig/3
|
-export([ aens_preclaim_sig/3
|
||||||
, aens_name_sig/4
|
, aens_name_sig/4
|
||||||
@ -25,7 +26,7 @@
|
|||||||
|
|
||||||
-type sig_data() :: binary().
|
-type sig_data() :: binary().
|
||||||
|
|
||||||
-spec aens_preclaim_sig(binary(), aeser_id:id(), aeser_id:id()) -> sig_data().
|
-spec aens_preclaim_sig(binary(), gmser_id:id(), gmser_id:id()) -> sig_data().
|
||||||
aens_preclaim_sig(NetworkId, Account, Contract) ->
|
aens_preclaim_sig(NetworkId, Account, Contract) ->
|
||||||
assert_id(account, Account),
|
assert_id(account, Account),
|
||||||
assert_id(contract, Contract),
|
assert_id(contract, Contract),
|
||||||
@ -33,7 +34,7 @@ aens_preclaim_sig(NetworkId, Account, Contract) ->
|
|||||||
Fields = [{account, Account}, {contract, Contract}],
|
Fields = [{account, Account}, {contract, Contract}],
|
||||||
serialize(?TYPE_AENS_PRECLAIM, NetworkId, Template, Fields).
|
serialize(?TYPE_AENS_PRECLAIM, NetworkId, Template, Fields).
|
||||||
|
|
||||||
-spec aens_name_sig(binary(), aeser_id:id(), aeser_id:id(), aeser_id:id()) -> sig_data().
|
-spec aens_name_sig(binary(), gmser_id:id(), gmser_id:id(), gmser_id:id()) -> sig_data().
|
||||||
aens_name_sig(NetworkId, Account, Name, Contract) ->
|
aens_name_sig(NetworkId, Account, Name, Contract) ->
|
||||||
assert_id(account, Account),
|
assert_id(account, Account),
|
||||||
assert_id(name, Name),
|
assert_id(name, Name),
|
||||||
@ -42,7 +43,7 @@ aens_name_sig(NetworkId, Account, Name, Contract) ->
|
|||||||
Fields = [{account, Account}, {name, Name}, {contract, Contract}],
|
Fields = [{account, Account}, {name, Name}, {contract, Contract}],
|
||||||
serialize(?TYPE_AENS_NAME, NetworkId, Template, Fields).
|
serialize(?TYPE_AENS_NAME, NetworkId, Template, Fields).
|
||||||
|
|
||||||
-spec aens_sig(binary(), aeser_id:id(), aeser_id:id()) -> sig_data().
|
-spec aens_sig(binary(), gmser_id:id(), gmser_id:id()) -> sig_data().
|
||||||
aens_sig(NetworkId, Account, Contract) ->
|
aens_sig(NetworkId, Account, Contract) ->
|
||||||
assert_id(account, Account),
|
assert_id(account, Account),
|
||||||
assert_id(contract, Contract),
|
assert_id(contract, Contract),
|
||||||
@ -56,8 +57,8 @@ aens_sig(NetworkId, Account, Contract) ->
|
|||||||
%% ------------------------------------------------------------------------
|
%% ------------------------------------------------------------------------
|
||||||
|
|
||||||
serialize(Type, NetworkId, Template, Fields) ->
|
serialize(Type, NetworkId, Template, Fields) ->
|
||||||
Data = aeserialization:serialize(Type, ?VSN, Template, Fields),
|
Data = gmserialization:serialize(Type, ?VSN, Template, Fields),
|
||||||
<<?DELEGATION_TAG:16, NetworkId/binary, Data/binary>>.
|
<<?DELEGATION_TAG:16, NetworkId/binary, Data/binary>>.
|
||||||
|
|
||||||
assert_id(Type, AeserId) ->
|
assert_id(Type, AeserId) ->
|
||||||
Type = aeser_id:specialize_type(AeserId).
|
Type = gmser_id:specialize_type(AeserId).
|
@ -1,12 +1,13 @@
|
|||||||
%%% -*- erlang-indent-level:4; indent-tabs-mode: nil -*-
|
%%% -*- erlang-indent-level:4; indent-tabs-mode: nil -*-
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @copyright (C) 2025, QPQ AG
|
||||||
%%% @copyright (C) 2018, Aeternity Anstalt
|
%%% @copyright (C) 2018, Aeternity Anstalt
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% ADT for identifiers
|
%%% ADT for identifiers
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
|
||||||
-module(aeser_id).
|
-module(gmser_id).
|
||||||
|
|
||||||
-export([ create/2
|
-export([ create/2
|
||||||
, specialize/1
|
, specialize/1
|
@ -1,4 +1,5 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @copyright (C) 2025, QPQ AG
|
||||||
%%% @copyright (C) 2017, Aeternity Anstalt
|
%%% @copyright (C) 2017, Aeternity Anstalt
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% Implementation of the Recursive Length Prefix.
|
%%% Implementation of the Recursive Length Prefix.
|
||||||
@ -8,7 +9,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
|
||||||
-module(aeser_rlp).
|
-module(gmser_rlp).
|
||||||
-export([ decode/1
|
-export([ decode/1
|
||||||
, decode_one/1
|
, decode_one/1
|
||||||
, encode/1
|
, encode/1
|
@ -1,5 +1,5 @@
|
|||||||
{application, aeserialization,
|
{application, gmserialization,
|
||||||
[{description, "Serialization of data for Aeternity"},
|
[{description, "Serialization of data for the Gajumaru"},
|
||||||
{vsn, "0.1.0"},
|
{vsn, "0.1.0"},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{applications,
|
{applications,
|
@ -1,11 +1,12 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @copyright (C) 2025, QPQ AG
|
||||||
%%% @copyright (C) 2018, Aeternity Anstalt
|
%%% @copyright (C) 2018, Aeternity Anstalt
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% Functions for serializing generic objects to/from binary format.
|
%%% Functions for serializing generic objects to/from binary format.
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
|
||||||
-module(aeserialization).
|
-module(gmserialization).
|
||||||
|
|
||||||
-export([ decode_fields/2
|
-export([ decode_fields/2
|
||||||
, deserialize/5
|
, deserialize/5
|
||||||
@ -37,7 +38,7 @@
|
|||||||
| [encodable_term()] %% Of any length
|
| [encodable_term()] %% Of any length
|
||||||
| #{atom() => encodable_term()}
|
| #{atom() => encodable_term()}
|
||||||
| tuple() %% Any arity, containing encodable_term().
|
| tuple() %% Any arity, containing encodable_term().
|
||||||
| aeser_id:id().
|
| gmser_id:id().
|
||||||
|
|
||||||
-type fields() :: [{field_name(), encodable_term()}].
|
-type fields() :: [{field_name(), encodable_term()}].
|
||||||
|
|
||||||
@ -49,13 +50,13 @@
|
|||||||
serialize(Tag, Vsn, Template, Fields) ->
|
serialize(Tag, Vsn, Template, Fields) ->
|
||||||
List = encode_fields([{tag, int}, {vsn, int}|Template],
|
List = encode_fields([{tag, int}, {vsn, int}|Template],
|
||||||
[{tag, Tag}, {vsn, Vsn}|Fields]),
|
[{tag, Tag}, {vsn, Vsn}|Fields]),
|
||||||
aeser_rlp:encode(List).
|
gmser_rlp:encode(List).
|
||||||
|
|
||||||
%% Type isn't strictly necessary, but will give a better error reason
|
%% Type isn't strictly necessary, but will give a better error reason
|
||||||
-spec deserialize(atom(), non_neg_integer(), non_neg_integer(),
|
-spec deserialize(atom(), non_neg_integer(), non_neg_integer(),
|
||||||
template(), binary()) -> fields().
|
template(), binary()) -> fields().
|
||||||
deserialize(Type, Tag, Vsn, Template0, Binary) ->
|
deserialize(Type, Tag, Vsn, Template0, Binary) ->
|
||||||
Decoded = aeser_rlp:decode(Binary),
|
Decoded = gmser_rlp:decode(Binary),
|
||||||
Template = [{tag, int}, {vsn, int}|Template0],
|
Template = [{tag, int}, {vsn, int}|Template0],
|
||||||
case decode_fields(Template, Decoded) of
|
case decode_fields(Template, Decoded) of
|
||||||
[{tag, Tag}, {vsn, Vsn}|Left] ->
|
[{tag, Tag}, {vsn, Vsn}|Left] ->
|
||||||
@ -68,7 +69,7 @@ deserialize(Type, Tag, Vsn, Template0, Binary) ->
|
|||||||
-spec deserialize_tag_and_vsn(binary()) ->
|
-spec deserialize_tag_and_vsn(binary()) ->
|
||||||
{non_neg_integer(), non_neg_integer(), fields()}.
|
{non_neg_integer(), non_neg_integer(), fields()}.
|
||||||
deserialize_tag_and_vsn(Binary) ->
|
deserialize_tag_and_vsn(Binary) ->
|
||||||
[TagBin, VsnBin|Fields] = aeser_rlp:decode(Binary),
|
[TagBin, VsnBin|Fields] = gmser_rlp:decode(Binary),
|
||||||
Template = [{tag, int}, {vsn, int}],
|
Template = [{tag, int}, {vsn, int}],
|
||||||
[{tag, Tag}, {vsn, Vsn}] = decode_fields(Template, [TagBin, VsnBin]),
|
[{tag, Tag}, {vsn, Vsn}] = decode_fields(Template, [TagBin, VsnBin]),
|
||||||
{Tag, Vsn, Fields}.
|
{Tag, Vsn, Fields}.
|
||||||
@ -118,7 +119,7 @@ encode_field(binary, X) when is_binary(X) -> X;
|
|||||||
encode_field(bool, true) -> <<1:8>>;
|
encode_field(bool, true) -> <<1:8>>;
|
||||||
encode_field(bool, false) -> <<0:8>>;
|
encode_field(bool, false) -> <<0:8>>;
|
||||||
encode_field(id, Val) ->
|
encode_field(id, Val) ->
|
||||||
try aeser_id:encode(Val)
|
try gmser_id:encode(Val)
|
||||||
catch _:_ -> error({illegal, id, Val})
|
catch _:_ -> error({illegal, id, Val})
|
||||||
end;
|
end;
|
||||||
encode_field(Type, Val) -> error({illegal, Type, Val}).
|
encode_field(Type, Val) -> error({illegal, Type, Val}).
|
||||||
@ -142,7 +143,7 @@ decode_field(binary, X) when is_binary(X) -> X;
|
|||||||
decode_field(bool, <<1:8>>) -> true;
|
decode_field(bool, <<1:8>>) -> true;
|
||||||
decode_field(bool, <<0:8>>) -> false;
|
decode_field(bool, <<0:8>>) -> false;
|
||||||
decode_field(id, Val) ->
|
decode_field(id, Val) ->
|
||||||
try aeser_id:decode(Val)
|
try gmser_id:decode(Val)
|
||||||
catch _:_ -> error({illegal, id, Val})
|
catch _:_ -> error({illegal, id, Val})
|
||||||
end;
|
end;
|
||||||
decode_field(Type, X) -> error({illegal, Type, X}).
|
decode_field(Type, X) -> error({illegal, Type, X}).
|
@ -1,12 +1,13 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @copyright (C) 2025, QPQ AG
|
||||||
%%% @copyright (C) 2018, Aeternity Anstalt
|
%%% @copyright (C) 2018, Aeternity Anstalt
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
|
||||||
-module(aeser_api_encoder_tests).
|
-module(gmser_api_encoder_tests).
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
-define(TEST_MODULE, aeser_api_encoder).
|
-define(TEST_MODULE, gmser_api_encoder).
|
||||||
-define(TYPES, [ {key_block_hash , 32}
|
-define(TYPES, [ {key_block_hash , 32}
|
||||||
, {micro_block_hash , 32}
|
, {micro_block_hash , 32}
|
||||||
, {block_tx_hash , 32}
|
, {block_tx_hash , 32}
|
@ -1,11 +1,12 @@
|
|||||||
%%% -*- erlang-indent-level:4; indent-tabs-mode: nil -*-
|
%%% -*- erlang-indent-level:4; indent-tabs-mode: nil -*-
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @copyright (C) 2025, QPQ AG
|
||||||
%%% @copyright (C) 2018, Aeternity Anstalt
|
%%% @copyright (C) 2018, Aeternity Anstalt
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% EUnit tests for aeser_chain_objects
|
%%% EUnit tests for gmser_chain_objects
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(aeser_chain_objects_tests).
|
-module(gmser_chain_objects_tests).
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
@ -78,10 +79,10 @@ deserialize(Template, Bin) ->
|
|||||||
deserialize(Template, Bin, ?DEFAULT_TAG, ?DEFAULT_VERSION).
|
deserialize(Template, Bin, ?DEFAULT_TAG, ?DEFAULT_VERSION).
|
||||||
|
|
||||||
deserialize(Template, Bin, Tag, Vsn) ->
|
deserialize(Template, Bin, Tag, Vsn) ->
|
||||||
aeser_chain_objects:deserialize(Tag, Vsn, Template, Bin).
|
gmser_chain_objects:deserialize(Tag, Vsn, Template, Bin).
|
||||||
|
|
||||||
serialize(Template, Bin) ->
|
serialize(Template, Bin) ->
|
||||||
serialize(Template, Bin, ?DEFAULT_TAG, ?DEFAULT_VERSION).
|
serialize(Template, Bin, ?DEFAULT_TAG, ?DEFAULT_VERSION).
|
||||||
|
|
||||||
serialize(Template, Bin, Tag, Vsn) ->
|
serialize(Template, Bin, Tag, Vsn) ->
|
||||||
aeser_chain_objects:serialize(Tag, Vsn, Template, Bin).
|
gmser_chain_objects:serialize(Tag, Vsn, Template, Bin).
|
@ -1,7 +1,11 @@
|
|||||||
-module(aeser_contract_code_tests).
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @copyright (C) 2025, QPQ AG
|
||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
|
||||||
|
-module(gmser_contract_code_tests).
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include("aeser_contract_code.hrl").
|
-include("gmser_contract_code.hrl").
|
||||||
|
|
||||||
-define(DUMMY_CODE_MAP_1,
|
-define(DUMMY_CODE_MAP_1,
|
||||||
#{ byte_code => <<"DUMMY CODE">>
|
#{ byte_code => <<"DUMMY CODE">>
|
||||||
@ -22,14 +26,14 @@
|
|||||||
, payable => true} ).
|
, payable => true} ).
|
||||||
|
|
||||||
vsn_1_test() ->
|
vsn_1_test() ->
|
||||||
aeser_contract_code:deserialize(
|
gmser_contract_code:deserialize(
|
||||||
aeser_contract_code:serialize(?DUMMY_CODE_MAP_1, ?SOPHIA_CONTRACT_VSN_1)).
|
gmser_contract_code:serialize(?DUMMY_CODE_MAP_1, ?SOPHIA_CONTRACT_VSN_1)).
|
||||||
|
|
||||||
vsn_2_test() ->
|
vsn_2_test() ->
|
||||||
aeser_contract_code:deserialize(
|
gmser_contract_code:deserialize(
|
||||||
aeser_contract_code:serialize(?DUMMY_CODE_MAP_2, ?SOPHIA_CONTRACT_VSN_2)).
|
gmser_contract_code:serialize(?DUMMY_CODE_MAP_2, ?SOPHIA_CONTRACT_VSN_2)).
|
||||||
|
|
||||||
vsn_3_test() ->
|
vsn_3_test() ->
|
||||||
aeser_contract_code:deserialize(
|
gmser_contract_code:deserialize(
|
||||||
aeser_contract_code:serialize(?DUMMY_CODE_MAP_3, ?SOPHIA_CONTRACT_VSN_3)).
|
gmser_contract_code:serialize(?DUMMY_CODE_MAP_3, ?SOPHIA_CONTRACT_VSN_3)).
|
||||||
|
|
@ -1,48 +1,49 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @copyright (C) 2025, QPQ AG
|
||||||
%%% @copyright (C) 2023, Aeternity Anstalt
|
%%% @copyright (C) 2023, Aeternity Anstalt
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
|
||||||
-module(aeser_delegation_tests).
|
-module(gmser_delegation_tests).
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
-define(TEST_MODULE, aeser_delegation).
|
-define(TEST_MODULE, gmser_delegation).
|
||||||
|
|
||||||
-define(ACCOUNT, aeser_id:create(account, <<1:256>>)).
|
-define(ACCOUNT, gmser_id:create(account, <<1:256>>)).
|
||||||
-define(CONTRACT, aeser_id:create(contract, <<2:256>>)).
|
-define(CONTRACT, gmser_id:create(contract, <<2:256>>)).
|
||||||
-define(NAME, aeser_id:create(name, <<3:256>>)).
|
-define(NAME, gmser_id:create(name, <<3:256>>)).
|
||||||
|
|
||||||
-define(NETWORK_ID, <<"my_fancy_network"/utf8>>).
|
-define(NETWORK_ID, <<"my_fancy_network"/utf8>>).
|
||||||
|
|
||||||
encode_correct_test_() ->
|
encode_correct_test_() ->
|
||||||
[{"Encode preclaim sig",
|
[{"Encode preclaim sig",
|
||||||
fun() ->
|
fun() ->
|
||||||
aeser_delegation:aens_preclaim_sig(?NETWORK_ID, ?ACCOUNT, ?CONTRACT)
|
gmser_delegation:aens_preclaim_sig(?NETWORK_ID, ?ACCOUNT, ?CONTRACT)
|
||||||
end},
|
end},
|
||||||
{"Encode name sig",
|
{"Encode name sig",
|
||||||
fun() ->
|
fun() ->
|
||||||
aeser_delegation:aens_name_sig(?NETWORK_ID, ?ACCOUNT, ?NAME, ?CONTRACT)
|
gmser_delegation:aens_name_sig(?NETWORK_ID, ?ACCOUNT, ?NAME, ?CONTRACT)
|
||||||
end},
|
end},
|
||||||
{"Encode aens wildcard sig",
|
{"Encode aens wildcard sig",
|
||||||
fun() ->
|
fun() ->
|
||||||
aeser_delegation:aens_sig(?NETWORK_ID, ?ACCOUNT, ?CONTRACT)
|
gmser_delegation:aens_sig(?NETWORK_ID, ?ACCOUNT, ?CONTRACT)
|
||||||
end}
|
end}
|
||||||
].
|
].
|
||||||
|
|
||||||
encode_fail_test_() ->
|
encode_fail_test_() ->
|
||||||
[{"Bad encoding preclaim sig",
|
[{"Bad encoding preclaim sig",
|
||||||
fun() ->
|
fun() ->
|
||||||
?assertError(_, aeser_delegation:aens_preclaim_sig(?NETWORK_ID, <<42:256>>, ?CONTRACT)),
|
?assertError(_, gmser_delegation:aens_preclaim_sig(?NETWORK_ID, <<42:256>>, ?CONTRACT)),
|
||||||
?assertError(_, aeser_delegation:aens_preclaim_sig(?NETWORK_ID, ?CONTRACT, ?ACCOUNT))
|
?assertError(_, gmser_delegation:aens_preclaim_sig(?NETWORK_ID, ?CONTRACT, ?ACCOUNT))
|
||||||
end},
|
end},
|
||||||
{"Bad encoding name sig",
|
{"Bad encoding name sig",
|
||||||
fun() ->
|
fun() ->
|
||||||
?assertError(_, aeser_delegation:aens_name_sig(?NETWORK_ID, ?ACCOUNT, <<42:256>>, ?CONTRACT)),
|
?assertError(_, gmser_delegation:aens_name_sig(?NETWORK_ID, ?ACCOUNT, <<42:256>>, ?CONTRACT)),
|
||||||
?assertError(_, aeser_delegation:aens_name_sig(?NETWORK_ID, ?NAME, ?ACCOUNT, ?CONTRACT))
|
?assertError(_, gmser_delegation:aens_name_sig(?NETWORK_ID, ?NAME, ?ACCOUNT, ?CONTRACT))
|
||||||
end},
|
end},
|
||||||
{"Bad encoding aens wildcard sig",
|
{"Bad encoding aens wildcard sig",
|
||||||
fun() ->
|
fun() ->
|
||||||
?assertError(_, aeser_delegation:aens_sig(?NETWORK_ID, ?ACCOUNT, <<42:256>>)),
|
?assertError(_, gmser_delegation:aens_sig(?NETWORK_ID, ?ACCOUNT, <<42:256>>)),
|
||||||
?assertError(_, aeser_delegation:aens_sig(?NETWORK_ID, ?CONTRACT, ?CONTRACT))
|
?assertError(_, gmser_delegation:aens_sig(?NETWORK_ID, ?CONTRACT, ?CONTRACT))
|
||||||
end}
|
end}
|
||||||
].
|
].
|
@ -1,10 +1,11 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @copyright (C) 2025, QPQ AG
|
||||||
%%% @copyright (C) 2017, Aeternity Anstalt
|
%%% @copyright (C) 2017, Aeternity Anstalt
|
||||||
%%% @doc Tests for Recursive Length Prefix
|
%%% @doc Tests for Recursive Length Prefix
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
|
||||||
-module(aeser_rlp_tests).
|
-module(gmser_rlp_tests).
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
@ -13,7 +14,7 @@
|
|||||||
-define(BYTE_ARRAY_OFFSET , 128).
|
-define(BYTE_ARRAY_OFFSET , 128).
|
||||||
-define(LIST_OFFSET , 192).
|
-define(LIST_OFFSET , 192).
|
||||||
|
|
||||||
-define(TEST_MODULE, aeser_rlp).
|
-define(TEST_MODULE, gmser_rlp).
|
||||||
|
|
||||||
rlp_one_byte_test() ->
|
rlp_one_byte_test() ->
|
||||||
B = <<42>>,
|
B = <<42>>,
|
Loading…
x
Reference in New Issue
Block a user