diff --git a/.gitignore b/.gitignore index ac706ed..8c94170 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea +.vscode *.abi *.wasm !/external/**/*.abi diff --git a/README.md b/README.md index e27885b..0ed9712 100644 --- a/README.md +++ b/README.md @@ -41,4 +41,24 @@ $ npm test > test > bun test -``` \ No newline at end of file +``` + +#### Exported memory errors + +``` +TypeError: undefined is not an object (evaluating 'this.memory.buffer') +``` + +If you're using a version of CDT to build that doesn't support exported memory, you'll need to export it manually for VeRT tests to work. + +```bash +# Grab wabt +sudo apt-get install wabt + +# Create a temporary wat file and export the memory +wasm2wat eosio.fees.wasm | sed -e 's|(memory |(memory (export "memory") |' > eosio.fees.wat +wat2wasm -o eosio.fees.wasm eosio.fees.wat +rm eosio.fees.wat +``` + +You can also use the `./build.sh` script that will handle building and exporting memory for you. \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..5651f82 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +cdt-cpp eosio.fees.cpp -I ./include +wasm2wat eosio.fees.wasm | sed -e 's|(memory |(memory (export "memory") |' > eosio.fees.wat +wat2wasm -o eosio.fees.wasm eosio.fees.wat +rm eosio.fees.wat \ No newline at end of file diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..7b520e3 Binary files /dev/null and b/bun.lockb differ diff --git a/eosio.fees.cpp b/eosio.fees.cpp index b32a45c..39b868c 100644 --- a/eosio.fees.cpp +++ b/eosio.fees.cpp @@ -5,6 +5,7 @@ namespace eosio { [[eosio::action]] void fees::init( const uint32_t epoch_time_interval ) { require_auth( get_self() ); + check( epoch_time_interval > 0, "epoch_time_interval must be greater than 0" ); settings_table _settings( get_self(), get_self().value ); auto settings = _settings.get_or_default(); @@ -55,7 +56,7 @@ void fees::distribute() update_next_epoch(); strategies_table _strategies( get_self(), get_self().value ); - const uint16_t total_weight = get_total_weight(); + const uint32_t total_weight = get_total_weight(); // distributing fees in EOS const asset balance = eosio::token::get_balance( "eosio.token"_n, get_self(), symbol_code("EOS") ); diff --git a/eosio.fees.hpp b/eosio.fees.hpp index 9d769a2..cdb69c9 100644 --- a/eosio.fees.hpp +++ b/eosio.fees.hpp @@ -116,9 +116,9 @@ namespace eosio { * @param contract - contract name * @return uint16_t - total weight */ - static uint16_t get_total_weight( const name contract = "eosio.fees"_n ) { + static uint32_t get_total_weight( const name contract = "eosio.fees"_n ) { strategies_table _strategies( contract, contract.value ); - uint16_t total_weight = 0; + uint32_t total_weight = 0; for (auto& row : _strategies) { total_weight += row.weight; } diff --git a/eosio.fees.spec.ts b/eosio.fees.spec.ts index 05d5a87..73a627c 100644 --- a/eosio.fees.spec.ts +++ b/eosio.fees.spec.ts @@ -91,6 +91,13 @@ describe(fees_contract, () => { ) }); + test("Cannot init with a 0 interval", async () => { + await expectToThrow( + contracts.fees.actions.init([0]).send(), + "eosio_assert: epoch_time_interval must be greater than 0" + ) + }); + test('eosio.fees::init', async () => { await contracts.fees.actions.init([TEN_MINUTES]).send()