Skip to content

Commit

Permalink
Update acceptance & integration tests to use the new configuration st…
Browse files Browse the repository at this point in the history
…yle (#251)

* Update acceptance & integration tests to use the new configuration style

* Update the kf file
  • Loading branch information
charithabandi authored and brennanjl committed Feb 26, 2024
1 parent baf7c9b commit 221858b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 199 deletions.
2 changes: 1 addition & 1 deletion test/acceptance/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
networks:
- kwil-act-testnet
command: |
--home=/app/kwil
--root_dir=/app/kwil
--log.log_level=${LOG_LEVEL:-info}
--app.extension_endpoints=ext:50051
--app.grpc_listen_addr=:50051
Expand Down
6 changes: 3 additions & 3 deletions test/integration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
depends_on:
- ext1
command: |
--home=/app/kwil
--root_dir=/app/kwil
--log.log_level=${LOG_LEVEL:-debug}
--app.extension_endpoints=ext1:50051
--app.grpc_listen_addr=:50051
Expand Down Expand Up @@ -50,7 +50,7 @@ services:
depends_on:
- ext1
command: |
--home=/app/kwil
--root_dir=/app/kwil
--log.log_level=${LOG_LEVEL:-info}
--app.extension_endpoints=ext1:50051
--app.grpc_listen_addr=:50051
Expand Down Expand Up @@ -78,7 +78,7 @@ services:
depends_on:
- ext1
command: |
--home=/app/kwil
--root_dir=/app/kwil
--log.log_level=${LOG_LEVEL:-info}
--app.extension_endpoints=ext1:50051
--app.grpc_listen_addr=:50051
Expand Down
188 changes: 0 additions & 188 deletions test/integration/test-data/test_db.json

This file was deleted.

62 changes: 55 additions & 7 deletions test/integration/test-data/test_db.kf
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
database testdb;

use math {
round: "up"
} as math_up;

use math {
round: "down"
} as math_down;

table users {
id int primary notnull,
username text default("sds"),
Expand All @@ -12,29 +20,41 @@ table posts {
user_id int,
title text,
content text maxlen(1000),
#unique_index unique(user_id, title)
#unique_index unique(user_id, title),
foreign_key (user_id) references users(id) on_delete do cascade on_update do cascade
}

action create_user($id, $username, $age) public {
INSERT INTO users (id, username, age, wallet)
VALUES ($id, $username, $age, @caller);
VALUES ($id, $username, $age, public_key(@caller, 'hex'));
}

action update_user($id, $username, $age) public {
UPDATE users
SET id = $id, username = $username, age = $age
WHERE wallet = public_key(@caller, 'hex');
}

action update_username($username) public {
UPDATE users
SET username = $username
WHERE wallet = @caller;
WHERE wallet = public_key(@caller, 'hex');
}

action delete_user() public {
DELETE FROM users
WHERE wallet = @caller;
WHERE wallet = public_key(@caller, 'hex');
}

action delete_user_by_id ($id) public owner {
DELETE FROM users
WHERE id = $id;
}

action create_post($id, $title, $content) private {
action create_post($id, $title, $content) public {
INSERT INTO posts (id, user_id, title, content)
VALUES ($id, (
SELECT id FROM users WHERE wallet = @caller
SELECT id FROM users WHERE wallet = public_key(@caller, 'hex')
), $title, $content);
}

Expand All @@ -43,7 +63,7 @@ action delete_post($id) public {
WHERE id = $id AND user_id = (
SELECT id
FROM users
WHERE wallet = @caller
WHERE wallet = public_key(@caller, 'hex')
);
}

Expand All @@ -58,6 +78,12 @@ action list_users() public {
FROM users;
}

action get_user_posts_by_userid($id) public {
SELECT title, content
FROM posts
WHERE user_id = $id;
}

action get_user_posts($username) public {
SELECT title, content
FROM posts
Expand All @@ -68,8 +94,30 @@ action get_user_posts($username) public {
);
}

action get_post_authenticated($id) public view mustsign {
SELECT *
FROM posts
WHERE id = $id;
}

action get_post_unauthenticated($id) public view {
SELECT *
FROM posts
WHERE id = $id;
}

action multi_select() public {
SELECT * FROM posts;

SELECT * FROM users;
}

action divide($numerator, $denominator) public view {
$up = math_up.div($numerator, $denominator);
$down = math_down.div($numerator, $denominator);
select $up AS upper_value, $down AS lower_value;
}

action owner_only() public owner view {
select 'owner only';
}

0 comments on commit 221858b

Please sign in to comment.