Skip to content

Commit

Permalink
Assert script len and document call script
Browse files Browse the repository at this point in the history
  • Loading branch information
digorithm committed Nov 30, 2021
1 parent 8fd235b commit 87117dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 0 additions & 1 deletion fuels-abigen-macro/tests/harness.rs
Expand Up @@ -655,7 +655,6 @@ async fn create_nested_struct_from_decoded_tokens() {

#[tokio::test]
async fn example_workflow() {
// @todo continue from here. Perform some more clean-up, uncomment the tests above, etc.
let rng = &mut StdRng::seed_from_u64(2322u64);

// Generates the bindings from the an ABI definition inline.
Expand Down
11 changes: 10 additions & 1 deletion fuels-rs/src/contract.rs
Expand Up @@ -64,7 +64,14 @@ impl Contract {
let script_data_offset = VM_TX_MEMORY + Transaction::script_offset() + script_len;
let script_data_offset = script_data_offset as Immediate12;

// Script to call the contract
// Script to call the contract.
// The offset that points to the `script_data`
// is loaded at the register `0x10`. Note that
// we're picking `0x10` simply because
// it could be any non-reserved register.
// Then, we use the Opcode to call a contract: `CALL`
// pointing at the register that we loaded the
// `script_data` at.
let script = vec![
Opcode::ADDI(0x10, REG_ZERO, script_data_offset),
Opcode::CALL(0x10, REG_ZERO, 0x10, REG_CGAS),
Expand All @@ -75,6 +82,8 @@ impl Contract {
.copied()
.collect::<Vec<u8>>();

assert!(script.len() == script_len, "Script length *must* be 16");

// `script_data` consists of:
// 1. The contract ID
// 2. The function selector
Expand Down

0 comments on commit 87117dd

Please sign in to comment.