Skip to content

Commit 50bb069

Browse files
fix: follow the js api in lambda sstore
Signed-off-by: Ivaylo Nikolov <[email protected]>
1 parent 85df9a6 commit 50bb069

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

src/hooks/lambda_s_store_transaction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ impl Default for LambdaSStoreTransactionData {
3939

4040
impl LambdaSStoreTransaction {
4141
/// Set the hook ID.
42-
pub fn hook_id(&mut self, hook_id: HookId) -> &mut Self {
42+
pub fn set_hook_id(&mut self, hook_id: HookId) -> &mut Self {
4343
self.data_mut().hook_id = Some(hook_id);
4444
self
4545
}
4646

4747
/// Set the storage updates.
48-
pub fn storage_updates(&mut self, storage_updates: Vec<LambdaStorageUpdate>) -> &mut Self {
48+
pub fn set_storage_updates(&mut self, storage_updates: Vec<LambdaStorageUpdate>) -> &mut Self {
4949
self.data_mut().storage_updates = storage_updates;
5050
self
5151
}
@@ -162,7 +162,7 @@ mod tests {
162162
let storage_update = LambdaStorageUpdate::StorageSlot(storage_slot);
163163

164164
let mut transaction = LambdaSStoreTransaction::new();
165-
transaction.hook_id(hook_id.clone()).add_storage_update(storage_update);
165+
transaction.set_hook_id(hook_id.clone()).add_storage_update(storage_update);
166166

167167
assert_eq!(transaction.get_hook_id(), Some(&hook_id));
168168
assert_eq!(transaction.get_storage_updates().len(), 1);

tests/e2e/hooks/lambda_sstore.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ async fn create_account_with_hook(
4545
let account_key = PrivateKey::generate_ed25519();
4646

4747
// Create initial storage slot (use minimal representation - no leading zeros)
48-
let storage_slot = LambdaStorageSlot::new(vec![0x01, 0x02, 0x03, 0x04], vec![0x05, 0x06, 0x07, 0x08]);
48+
let storage_slot =
49+
LambdaStorageSlot::new(vec![0x01, 0x02, 0x03, 0x04], vec![0x05, 0x06, 0x07, 0x08]);
4950

5051
// Create lambda hook with storage
5152
let spec = EvmHookSpec::new(Some(contract_id));
52-
let lambda_hook = LambdaEvmHook::new(spec, vec![LambdaStorageUpdate::StorageSlot(storage_slot)]);
53+
let lambda_hook =
54+
LambdaEvmHook::new(spec, vec![LambdaStorageUpdate::StorageSlot(storage_slot)]);
5355

5456
let hook_details =
5557
HookCreationDetails::new(HookExtensionPoint::AccountAllowanceHook, 1, Some(lambda_hook));
@@ -82,15 +84,17 @@ async fn can_update_storage_slots_with_valid_signatures() -> anyhow::Result<()>
8284
};
8385

8486
let contract_id = create_hook_contract(&client).await?;
85-
let (_account_id, account_key, hook_id) = create_account_with_hook(&client, contract_id).await?;
87+
let (_account_id, account_key, hook_id) =
88+
create_account_with_hook(&client, contract_id).await?;
8689

8790
// Create new storage update (use minimal representation - no leading zeros)
88-
let new_storage_slot = LambdaStorageSlot::new(vec![0x09, 0x0a, 0x0b, 0x0c], vec![0x0d, 0x0e, 0x0f, 0x10]);
91+
let new_storage_slot =
92+
LambdaStorageSlot::new(vec![0x09, 0x0a, 0x0b, 0x0c], vec![0x0d, 0x0e, 0x0f, 0x10]);
8993
let storage_update = LambdaStorageUpdate::StorageSlot(new_storage_slot);
9094

9195
// Update storage slots
9296
let receipt = LambdaSStoreTransaction::new()
93-
.hook_id(hook_id)
97+
.set_hook_id(hook_id)
9498
.add_storage_update(storage_update)
9599
.freeze_with(&client)?
96100
.sign(account_key)
@@ -111,16 +115,18 @@ async fn cannot_update_more_than_256_storage_slots() -> anyhow::Result<()> {
111115
};
112116

113117
let contract_id = create_hook_contract(&client).await?;
114-
let (_account_id, account_key, hook_id) = create_account_with_hook(&client, contract_id).await?;
118+
let (_account_id, account_key, hook_id) =
119+
create_account_with_hook(&client, contract_id).await?;
115120

116121
// Create 257 storage slots (exceeds limit)
117-
let storage_slot = LambdaStorageSlot::new(vec![0x01, 0x02, 0x03, 0x04], vec![0x05, 0x06, 0x07, 0x08]);
122+
let storage_slot =
123+
LambdaStorageSlot::new(vec![0x01, 0x02, 0x03, 0x04], vec![0x05, 0x06, 0x07, 0x08]);
118124
let storage_updates: Vec<LambdaStorageUpdate> =
119125
(0..257).map(|_| LambdaStorageUpdate::StorageSlot(storage_slot.clone())).collect();
120126

121127
let result = LambdaSStoreTransaction::new()
122-
.hook_id(hook_id)
123-
.storage_updates(storage_updates)
128+
.set_hook_id(hook_id)
129+
.set_storage_updates(storage_updates)
124130
.freeze_with(&client)?
125131
.sign(account_key)
126132
.execute(&client)
@@ -149,16 +155,18 @@ async fn cannot_update_storage_with_invalid_signature() -> anyhow::Result<()> {
149155
};
150156

151157
let contract_id = create_hook_contract(&client).await?;
152-
let (_account_id, _account_key, hook_id) = create_account_with_hook(&client, contract_id).await?;
158+
let (_account_id, _account_key, hook_id) =
159+
create_account_with_hook(&client, contract_id).await?;
153160

154161
// Use wrong key
155162
let invalid_key = PrivateKey::generate_ed25519();
156163

157-
let storage_slot = LambdaStorageSlot::new(vec![0x31, 0x32, 0x33, 0x34], vec![0x35, 0x36, 0x37, 0x38]);
164+
let storage_slot =
165+
LambdaStorageSlot::new(vec![0x31, 0x32, 0x33, 0x34], vec![0x35, 0x36, 0x37, 0x38]);
158166
let storage_update = LambdaStorageUpdate::StorageSlot(storage_slot);
159167

160168
let result = LambdaSStoreTransaction::new()
161-
.hook_id(hook_id)
169+
.set_hook_id(hook_id)
162170
.add_storage_update(storage_update)
163171
.freeze_with(&client)?
164172
.sign(invalid_key)
@@ -185,13 +193,15 @@ async fn cannot_update_storage_for_nonexistent_hook() -> anyhow::Result<()> {
185193
};
186194

187195
let contract_id = create_hook_contract(&client).await?;
188-
let (account_id, account_key, _hook_id) = create_account_with_hook(&client, contract_id).await?;
196+
let (account_id, account_key, _hook_id) =
197+
create_account_with_hook(&client, contract_id).await?;
189198

190199
// Use non-existent hook ID
191200
let entity_id = HookEntityId::new(Some(account_id));
192201
let nonexistent_hook_id = HookId::new(Some(entity_id), 999);
193202

194-
let storage_slot = LambdaStorageSlot::new(vec![0x41, 0x42, 0x43, 0x44], vec![0x45, 0x46, 0x47, 0x48]);
203+
let storage_slot =
204+
LambdaStorageSlot::new(vec![0x41, 0x42, 0x43, 0x44], vec![0x45, 0x46, 0x47, 0x48]);
195205
let storage_update = LambdaStorageUpdate::StorageSlot(storage_slot);
196206

197207
let result = LambdaSStoreTransaction::new()
@@ -224,7 +234,8 @@ async fn can_update_multiple_storage_slots() -> anyhow::Result<()> {
224234
};
225235

226236
let contract_id = create_hook_contract(&client).await?;
227-
let (_account_id, account_key, hook_id) = create_account_with_hook(&client, contract_id).await?;
237+
let (_account_id, account_key, hook_id) =
238+
create_account_with_hook(&client, contract_id).await?;
228239

229240
// Create multiple storage updates
230241
let storage_slot1 =
@@ -242,8 +253,8 @@ async fn can_update_multiple_storage_slots() -> anyhow::Result<()> {
242253

243254
// Update multiple storage slots at once
244255
let receipt = LambdaSStoreTransaction::new()
245-
.hook_id(hook_id)
246-
.storage_updates(storage_updates)
256+
.set_hook_id(hook_id)
257+
.set_storage_updates(storage_updates)
247258
.freeze_with(&client)?
248259
.sign(account_key)
249260
.execute(&client)

0 commit comments

Comments
 (0)