Los 19 extrinsics de provenance/fees/agent-identity/emission/governance pasan de weights placeholder `from_parts(10_000, 0)` (proof_size=0, sin contar reads/writes de DB — vector de DoS real) a weights INTERIM hand-derived DB-aware vía el trait `WeightInfo`. Cierra el mispricing de DoS en TODOS los extrinsics del chain. Cada pallet gana: - weights.rs: trait WeightInfo + SubstrateWeight<T> (DB-aware vía T::DbWeight) + impl () - benchmarking.rs: benchmarks FRAME v2, VERIFICADOS por impl_benchmark_test_suite! (19 benchmarks ejecutan+pasan en los mocks — cargo test --features runtime-benchmarks) - Config: `type WeightInfo` + swap de los `#[pallet::weight]` Runtime: - define_benchmarks! con los 5 pallets + runtime API Benchmark (inerte sin la feature) - WeightInfo cableado a SubstrateWeight<Runtime> en cada Config - RUNTIME_VERSION 8→9 (weights = consenso-relevante: fee + llenado de bloque; las firmas de los extrinsics NO cambian ⇒ TRANSACTION_VERSION intacto) 3 bugs latentes cerrados (territorio virgen — el runtime NUNCA se compiló con runtime-benchmarks; las dimensiones nuevas cazan lo que no se había visto): - pallet-grandpa/try-runtime mal ubicado en la feature runtime-benchmarks (copy-paste erróneo: features ortogonales; NUNCA activaba los benchmarks de grandpa) - feature runtime-benchmarks incompleta → E0046 en OriginFeeAdapter (métodos benchmark-gated de OnChargeTransaction) + pallet-staking (StakingUnchecked::migrate_to_direct_staker); ahora lista TODOS los pallets como un runtime de producción Substrate - pallet-revive/runtime-benchmarks omitido a propósito (fixtures RISC-V/PolkaVM indisponibles; ReviveApi deferred, no benchmarkeado) emission: mock extraído del `mod tests` inline a `pub mod mock` (reuso del test-suite, sin duplicar el scaffold; los 15 tests existentes + el benchmark verdes). GATED (documentado en el §Estado de cada weights.rs): la generación de números CANÓNICOS por CLI requiere el node sc-service o omni-bencher+WASM (ambos bloqueados hace sesiones). Los weights interinos son DB-aware/DoS-safe y regenerables de forma mecánica cuando aterrice el HW de referencia (Pi5/VPS) — benchmarking.rs es la fuente de verdad de la FORMA. Verificado: 5 test-suites de pallet verdes (con y sin runtime-benchmarks) + runtime compila en ambos modos + workspace sin regresión + 40 tests de runtime (incl. v9). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
88 lines
3.1 KiB
Rust
88 lines
3.1 KiB
Rust
//! # Mock runtime para integration tests
|
||
//!
|
||
//! Mock minimal (`System` + `Provenance`) para E2E del flow PROV-3 + FIX-4:
|
||
//! decode postcard → gates → Ed25519 verify domain-separado → anclar.
|
||
//!
|
||
//! FIX-4: `new_test_ext_with_genesis` siembra `block_hash(0)` = el genesis con
|
||
//! el que se firmaron los golden vectors (generados desde el oráculo REAL de
|
||
//! Ergon `arkhe-noesis-core`), para probar la verificación cross-runtime.
|
||
|
||
#![cfg(test)]
|
||
|
||
use crate as origin_chain_provenance;
|
||
use frame_support::derive_impl;
|
||
use sp_core::H256;
|
||
use sp_runtime::BuildStorage;
|
||
|
||
/// Mock block type para tests.
|
||
type Block = frame_system::mocking::MockBlock<Test>;
|
||
|
||
frame_support::construct_runtime!(
|
||
pub enum Test {
|
||
System: frame_system,
|
||
Provenance: origin_chain_provenance,
|
||
}
|
||
);
|
||
|
||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
|
||
impl frame_system::Config for Test {
|
||
type Block = Block;
|
||
type AccountId = sp_runtime::AccountId32;
|
||
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
|
||
}
|
||
|
||
impl origin_chain_provenance::Config for Test {
|
||
type RuntimeEvent = RuntimeEvent;
|
||
type WeightInfo = ();
|
||
}
|
||
|
||
/// Genesis hash de los golden vectors ASP-3 (`/tmp/golden-asp3`, GENESIS=0xAB×32).
|
||
/// El pallet lee `block_hash(0)`; el mock lo siembra con ESTE valor para que la
|
||
/// verificación Ed25519 coincida con las firmas del oráculo.
|
||
pub const GOLDEN_GENESIS: [u8; 32] = [0xABu8; 32];
|
||
|
||
/// Pubkey del validador golden (seed [7u8;32] → todos los vectores la usan).
|
||
pub const GOLDEN_VALIDATOR_PUBKEY: [u8; 32] = [
|
||
0xea, 0x4a, 0x6c, 0x63, 0xe2, 0x9c, 0x52, 0x0a, 0xbe, 0xf5, 0x50, 0x7b, 0x13, 0x2e, 0xc5, 0xf9,
|
||
0x95, 0x47, 0x76, 0xae, 0xbe, 0xbe, 0x7b, 0x92, 0x42, 0x1e, 0xea, 0x69, 0x14, 0x46, 0xd2, 0x2c,
|
||
];
|
||
|
||
/// Registra el validador golden con el nivel dado (vía Root) — helper de tests.
|
||
pub fn register_golden_validator(level: u8) {
|
||
crate::pallet::Pallet::<Test>::register_validator(
|
||
RuntimeOrigin::root(),
|
||
GOLDEN_VALIDATOR_PUBKEY,
|
||
level,
|
||
)
|
||
.expect("Root registra el validador");
|
||
}
|
||
|
||
/// Test externalities con `block_hash(0)` sembrado al genesis dado.
|
||
pub fn new_test_ext_with_genesis(genesis: [u8; 32]) -> sp_io::TestExternalities {
|
||
let mut ext: sp_io::TestExternalities = frame_system::GenesisConfig::<Test>::default()
|
||
.build_storage()
|
||
.expect("genesis builds")
|
||
.into();
|
||
ext.execute_with(|| {
|
||
System::set_block_number(1);
|
||
// Siembra el hash del bloque génesis (que el pallet lee para el dominio).
|
||
frame_system::BlockHash::<Test>::insert(0u64, H256(genesis));
|
||
});
|
||
ext
|
||
}
|
||
|
||
/// Test externalities con el genesis de los golden vectors (caso por defecto).
|
||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||
new_test_ext_with_genesis(GOLDEN_GENESIS)
|
||
}
|
||
|
||
/// Submitter de prueba (un relayer cualquiera — paga el fee, no es el validador).
|
||
pub fn alice_origin() -> RuntimeOrigin {
|
||
RuntimeOrigin::signed(sp_runtime::AccountId32::new([1u8; 32]))
|
||
}
|
||
|
||
/// Segundo submitter (BOB).
|
||
pub fn bob_origin() -> RuntimeOrigin {
|
||
RuntimeOrigin::signed(sp_runtime::AccountId32::new([2u8; 32]))
|
||
}
|