Skip to content

Commit 63096d5

Browse files
committed
add test
1 parent 2e128ac commit 63096d5

File tree

2 files changed

+353
-91
lines changed

2 files changed

+353
-91
lines changed

src/test/app/SetHook_test.cpp

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,6 +3250,148 @@ class SetHook0_test : public beast::unit_test::suite
32503250
ter(temMALFORMED));
32513251
env.close();
32523252
}
3253+
3254+
// Test 8: guard inside guard
3255+
{
3256+
/*
3257+
#include <stdint.h>
3258+
extern int32_t _g(uint32_t id, uint32_t maxiter);
3259+
extern int64_t accept(uint32_t read_ptr, uint32_t read_len, int64_t
3260+
error_code);
3261+
3262+
int64_t helper(int64_t n) {
3263+
int64_t sum = n;
3264+
for (int i = 0; i < 100; ++i) {
3265+
_g(2, 1000);
3266+
sum += i;
3267+
}
3268+
return sum;
3269+
}
3270+
3271+
int64_t cbak(uint32_t reserved) {
3272+
_g(1, 1);
3273+
int64_t result = 10;
3274+
for (int i = 0; i < 10; ++i) {
3275+
_g(3, 11);
3276+
result += helper(10);
3277+
}
3278+
return accept(0, 0, result);
3279+
}
3280+
3281+
int64_t hook(uint32_t reserved) {
3282+
_g(1, 1);
3283+
int64_t result = 0;
3284+
for (int i = 0; i < 10; ++i) {
3285+
_g(3, 11);
3286+
result += helper(0);
3287+
}
3288+
return accept(0, 0, result);
3289+
}
3290+
*/
3291+
3292+
TestHook hook_wasm = wasm[R"[test.hook](
3293+
(module
3294+
(type (;0;) (func (param i32) (result i64)))
3295+
(type (;1;) (func (param i32 i32) (result i32)))
3296+
(type (;2;) (func (param i32 i32 i64) (result i64)))
3297+
(type (;3;) (func (param i64) (result i64)))
3298+
(import "env" "_g" (func (;0;) (type 1)))
3299+
(import "env" "accept" (func (;1;) (type 2)))
3300+
(func (;2;) (type 3) (param i64) (result i64)
3301+
(local i64)
3302+
i64.const 100
3303+
local.set 1
3304+
loop ;; label = @1
3305+
i32.const 2
3306+
i32.const 1000
3307+
call 0
3308+
drop
3309+
local.get 1
3310+
i64.const 1
3311+
i64.sub
3312+
local.tee 1
3313+
i64.eqz
3314+
i32.eqz
3315+
br_if 0 (;@1;)
3316+
end
3317+
local.get 0
3318+
i64.const 4950
3319+
i64.add)
3320+
(func (;3;) (type 0) (param i32) (result i64)
3321+
(local i64)
3322+
i32.const 1
3323+
i32.const 1
3324+
call 0
3325+
drop
3326+
i32.const 10
3327+
local.set 0
3328+
i64.const 10
3329+
local.set 1
3330+
loop ;; label = @1
3331+
i32.const 3
3332+
i32.const 11
3333+
call 0
3334+
drop
3335+
i64.const 10
3336+
call 2
3337+
local.get 1
3338+
i64.add
3339+
local.set 1
3340+
local.get 0
3341+
i32.const 1
3342+
i32.sub
3343+
local.tee 0
3344+
br_if 0 (;@1;)
3345+
end
3346+
i32.const 0
3347+
i32.const 0
3348+
local.get 1
3349+
call 1)
3350+
(func (;4;) (type 0) (param i32) (result i64)
3351+
(local i64)
3352+
i32.const 1
3353+
i32.const 1
3354+
call 0
3355+
drop
3356+
i32.const 10
3357+
local.set 0
3358+
loop ;; label = @1
3359+
i32.const 3
3360+
i32.const 11
3361+
call 0
3362+
drop
3363+
i64.const 0
3364+
call 2
3365+
local.get 1
3366+
i64.add
3367+
local.set 1
3368+
local.get 0
3369+
i32.const 1
3370+
i32.sub
3371+
local.tee 0
3372+
br_if 0 (;@1;)
3373+
end
3374+
i32.const 0
3375+
i32.const 0
3376+
local.get 1
3377+
call 1)
3378+
(memory (;0;) 2)
3379+
(export "memory" (memory 0))
3380+
(export "cbak" (func 3))
3381+
(export "hook" (func 4)))
3382+
)[test.hook]"];
3383+
HASH_WASM(hook);
3384+
3385+
env(ripple::test::jtx::hook(
3386+
alice, {{hso(hook_wasm, overrideFlag)}}, 0),
3387+
M("guard inside guard"),
3388+
HSFEE,
3389+
ter(tesSUCCESS));
3390+
EXPECT_HOOK_FEE(hook, 9151);
3391+
3392+
env(pay(bob, alice, XRP(1)), M("Test helper 8"), fee(XRP(1)));
3393+
env.close();
3394+
}
32533395
}
32543396

32553397
void

0 commit comments

Comments
 (0)