Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ The `args.json` file should contain an array of constructor argument expressions

The compiled JSON output includes:
- `contract_name`: The name of the contract
- `compiler_version`: The SilverScript compiler version that produced the artifact
- `script`: The compiled bytecode (as an array of bytes)
- `ast`: The abstract syntax tree of the parsed contract
- `abi`: An array of entrypoint functions with their parameter types
Expand Down Expand Up @@ -132,6 +133,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let compiled = compile_contract(source, &constructor_args, options)?;

println!("Contract name: {}", compiled.contract_name);
println!("Compiler version: {}", compiled.compiler_version);
println!("Script length: {} bytes", compiled.script.len());
println!("ABI: {:?}", compiled.abi);

Expand Down
1 change: 1 addition & 0 deletions silverscript-lang/src/compiler/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ fn build_compiled_contract<'i>(
) -> CompiledContract<'i> {
CompiledContract {
contract_name: lowered_contract.name.clone(),
compiler_version: COMPILER_VERSION.to_string(),
script,
ast: covenant_lowered_contract.clone(),
abi: function_abi_entries,
Expand Down
1 change: 1 addition & 0 deletions silverscript-lang/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub struct CompiledStateLayout {
#[derive(Debug, Serialize, Deserialize)]
pub struct CompiledContract<'i> {
pub contract_name: String,
pub compiler_version: String,
pub script: Vec<u8>,
pub ast: ContractAst<'i>,
pub abi: Vec<FunctionAbiEntry>,
Expand Down
9 changes: 8 additions & 1 deletion silverscript-lang/tests/compiler_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use kaspa_txscript::{
};
use silverscript_lang::ast::{Expr, ExprKind, Statement, format_contract_ast, parse_contract_ast};
use silverscript_lang::compiler::{
CompileOptions, CompiledContract, CovenantDeclCallOptions, FunctionAbiEntry, FunctionInputAbi, compile_contract,
COMPILER_VERSION, CompileOptions, CompiledContract, CovenantDeclCallOptions, FunctionAbiEntry, FunctionInputAbi, compile_contract,
compile_contract_ast, function_branch_index, generated_covenant_auth_entrypoint_name, struct_object,
};
use silverscript_lang::debug_info::StepKind;
Expand Down Expand Up @@ -183,6 +183,13 @@ fn accepts_missing_pragma_without_version_check() {
compile_contract(&source, &[], CompileOptions::default()).expect("contract without pragma should still compile");
}

#[test]
fn compiled_contract_includes_compiler_version() {
let source = pragma_source(None);
let compiled = compile_contract(&source, &[], CompileOptions::default()).expect("compile succeeds");
assert_eq!(compiled.compiler_version, COMPILER_VERSION);
}

#[test]
fn rejects_incompatible_pragma_versions() {
let pragmas = [
Expand Down
4 changes: 3 additions & 1 deletion silverscript-lang/tests/silverc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use kaspa_txscript::script_builder::ScriptBuilder;
use kaspa_txscript::{EngineCtx, EngineFlags, TxScriptEngine};
use rand::RngCore;
use silverscript_lang::ast::ContractAst;
use silverscript_lang::compiler::{CompiledContract, function_branch_index};
use silverscript_lang::compiler::{COMPILER_VERSION, CompiledContract, function_branch_index};

fn contract_fixture(name: &str) -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("tests").join("silverc-test-files").join(name)
Expand Down Expand Up @@ -83,6 +83,7 @@ fn silverc_defaults_output_path_and_empty_ctor_args() {
let json = fs::read_to_string(&out_path).expect("read output");
let compiled: CompiledContract = serde_json::from_str(&json).expect("parse compiled contract");
assert_eq!(compiled.contract_name, "Basic");
assert_eq!(compiled.compiler_version, COMPILER_VERSION);
}

#[test]
Expand Down Expand Up @@ -122,6 +123,7 @@ fn silverc_accepts_constructor_args_and_output_flag() {
let json = fs::read_to_string(&out_path).expect("read output");
let compiled: CompiledContract = serde_json::from_str(&json).expect("parse compiled contract");
assert_eq!(compiled.contract_name, "WithCtor");
assert_eq!(compiled.compiler_version, COMPILER_VERSION);
let selector =
if compiled.without_selector { None } else { Some(function_branch_index(&compiled.ast, "main").expect("selector resolved")) };
assert!(run_script_with_selector(compiled.script, selector).is_ok());
Expand Down