Skip to content

Commit

Permalink
add bash script
Browse files Browse the repository at this point in the history
  • Loading branch information
zsluedem committed Mar 28, 2024
1 parent d514bce commit 76ea3f3
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ const leaves = data.map((d) =>
const tree = new merkle.MerkleTree(leaves, hash.computePoseidonHash);
console.log("root: ", tree.root)

const h = hash_posei([7, 2, 100, 130, 90, 25, 1, 2160, 1700])
const h = hash_posei([8, 1, 210, 140, 260, 120, 4, 2000, 100])
console.log("h: ", h)
const proof = tree.getProof(h);
console.log("proof: ", proof)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "node index.js",
"test": "node test_index.js",
"main": "node index.js",
"debug": "node inspect index.js"
},
"author": "",
Expand Down
6 changes: 4 additions & 2 deletions scripts/default_auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ echo actions : $ACTIONS_ADDRESS
echo "---------------------------------------------------------------------------"

# enable system -> component authorizations
COMPONENTS=("Barn" "OuterCity" "Warehouse" "CityBuilding" "SpawnStatus" "UnderUpgrading" "CityHall", "BuildingAreaInfo" "Barrack" "Troops" "UnderTraining" "BarnStorage" "WarehouseStorage")
COMPONENTS=("Barn" "OuterCity" "Warehouse" "CityBuilding" "SpawnStatus" "UnderUpgrading" "CityHall" "BuildingAreaInfo" "Barrack" "Troops" "UnderTraining" "BarnStorage" "WarehouseStorage")

for component in ${COMPONENTS[@]}; do
sozo auth writer $component $ACTIONS_ADDRESS --world $WORLD_ADDRESS --rpc-url $RPC_URL
Expand All @@ -39,5 +39,7 @@ echo "Default authorizations have been successfully set."

echo "Setting pay address for upgrading"
export ADMIN_ADDRESS=$(cat ./target/$TARGET_NAME/manifest.json | jq -r '.contracts[] | select(.name == "kingdom_lord::admin::kingdom_lord_admin" ).address')
sozo execute 0x17acb0793d3bfdf9b8058d6ba25215bed0df3949007d0b7676ad335736e444f set_config --calldata 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7,0,100,0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03,0x2e3aa949c5d014218a1194b9d5c84c7457a027fc34826547b8dfe5b52d72220
sozo execute 0x17acb0793d3bfdf9b8058d6ba25215bed0df3949007d0b7676ad335736e444f \
set_config --calldata 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7,0,100,0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03,0x2e3aa949c5d014218a1194b9d5c84c7457a027fc34826547b8dfe5b52d72220 \
--rpc-url $RPC_URL
echo "Setting pay address for upgrading done"
9 changes: 9 additions & 0 deletions scripts/gen_block.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set +xo pipefail

while true; do
sozo execute --private-key 0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a --account-address 0xb3ff441a68610b30fd5e2abbf3a1548eb6ba6f3559f2862bf2dc757e5828ca --rpc-url http://localhost:5050 \
0x1c9c0eac696e8b998fd586792939e7d902312e08ec45b6795de12e52b723e10 get_resource --calldata 0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a
sleep 1
done
4 changes: 4 additions & 0 deletions scripts/test/finish_upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sozo execute --private-key 0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912 \
--account-address 0x29873c310fbefde666dc32a1554fea6bb45eecc84f680f8a2b0a8fbb8cb89af \
0x1c9c0eac696e8b998fd586792939e7d902312e08ec45b6795de12e52b723e10 finish_upgrade \
--calldata 0
4 changes: 4 additions & 0 deletions scripts/test/get_complete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
starkli call 0x1c9c0eac696e8b998fd586792939e7d902312e08ec45b6795de12e52b723e10 \
0x00d750558670976360b71b7082077d5d849a1f5ca1151ec81e6982526bb20a9a \
0x29873c310fbefde666dc32a1554fea6bb45eecc84f680f8a2b0a8fbb8cb89af \
--rpc http://localhost:5050
4 changes: 4 additions & 0 deletions scripts/test/get_upgrading.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
starkli call 0x1c9c0eac696e8b998fd586792939e7d902312e08ec45b6795de12e52b723e10 \
0x028a4e3deda5d3e3528954bc5786423590f83618037292480e17031b8a7a3d5e \
0x29873c310fbefde666dc32a1554fea6bb45eecc84f680f8a2b0a8fbb8cb89af \
--rpc http://localhost:5050
3 changes: 3 additions & 0 deletions scripts/test/spawn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sozo execute --private-key 0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912 \
--account-address 0x29873c310fbefde666dc32a1554fea6bb45eecc84f680f8a2b0a8fbb8cb89af \
0x1c9c0eac696e8b998fd586792939e7d902312e08ec45b6795de12e52b723e10 spawn
4 changes: 4 additions & 0 deletions scripts/test/upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sozo execute --private-key 0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912 \
--account-address 0x29873c310fbefde666dc32a1554fea6bb45eecc84f680f8a2b0a8fbb8cb89af \
0x1c9c0eac696e8b998fd586792939e7d902312e08ec45b6795de12e52b723e10 start_upgrade \
--calldata 21,5,1,70,40,60,20,2,2500,100,8,0x56e9e5ce79486d11d4079f6521d5de93bc3e474dc2cd647063fe45c22054ac8,0x575978c19ae8821f17dcb09f2865515b661bb72486a758da18853b0208c5081,0x751fea1cdd1b21696ae357f83c2b96fbd0a7891b053cdc652807c88320c942c,0x352510f1269cea2ac10dab006a027dee2dcc6fc82676fbb5b862269d99528ee,0x660a74333a6082be847d98d1779c25ab498eaf93ea998125db323a1bc0c8cc7,0x53292aa62ac71f440a6c19786b359d3242844aed9effad78c0e7972ef409a1b,0x59dc966df9f4d4b5a02fa4d584ce7280cc0c8633e411a3f92f558abe1ecc464,0x6f083eb9dc40b555e9f8c6ed4529c2c5bfd33087c0f80701992b254230a0c32
12 changes: 8 additions & 4 deletions src/actions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,13 @@ mod kingdom_lord_controller {
let curr_building_kind = self.universal.building_kind(building_id);

if building_kind != curr_building_kind && curr_building_kind != BuildingKind::None {
return Result::Err(Error::UnknownedError('invalid building kind'));
panic!("invalid building kind");
// return Result::Err(Error::UnknownedError('invalid building kind'));
}

if !self.universal.is_next_level_valid(building_id, building_kind, next_level) {
return Result::Err(Error::UnknownedError('next level is not valid'));
panic!("next level is not valid");
// return Result::Err(Error::UnknownedError('next level is not valid'));
}

let req_wood = req_wood.into();
Expand All @@ -340,13 +342,15 @@ mod kingdom_lord_controller {
let (wood, brick, steel, food) = self.get_resource(caller_address);
if wood < req_wood || brick < req_brick || steel < req_steel || food < req_food {
self.emit(UpgradeNotEnoughResourceEvent { player: caller_address, building_id });
return Result::Err(Error::ResourceNotEnough);
panic!("resource not enough");
// return Result::Err(Error::ResourceNotEnough);
}

let world = self.world_dispatcher.read();
let config = get!(world, (CONFIG_ID), (Config));
if !verify_proof(config, data.span(), proof.span()) {
return Result::Err(Error::InvalidProof);
panic!("invalid proof");
// return Result::Err(Error::InvalidProof);
}

let is_new_building = curr_building_kind == BuildingKind::None;
Expand Down
4 changes: 4 additions & 0 deletions src/tests/test_city_hall.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ mod tests {
let upgrade_id =res.unwrap();
assert(upgrade_id == 0, 'first upgrade id is 0');

let under_upgrade = context.kingdom_lord.get_under_upgrading(caller);
let upgrade = under_upgrade.at(0);
assert(under_upgrade.len() == 1, 'under_upgrade should be 1');

increase_time(2500);

let finishe_upgrade = context.kingdom_lord.get_complete_upgrading(caller);
Expand Down
Empty file added test_index.js
Empty file.

0 comments on commit 76ea3f3

Please sign in to comment.