Skip to main content

tempo_precompiles/tip20_factory/
dispatch.rs

1//! ABI dispatch for the [`TIP20Factory`] precompile.
2
3use crate::{
4    Precompile, charge_input_cost, dispatch_call, mutate, tip20_factory::TIP20Factory, view,
5};
6use alloy::{primitives::Address, sol_types::SolInterface};
7use revm::precompile::PrecompileResult;
8use tempo_contracts::precompiles::ITIP20Factory::ITIP20FactoryCalls;
9
10impl Precompile for TIP20Factory {
11    fn call(&mut self, calldata: &[u8], msg_sender: Address) -> PrecompileResult {
12        if let Some(err) = charge_input_cost(&mut self.storage, calldata) {
13            return err;
14        }
15
16        dispatch_call(
17            calldata,
18            &[],
19            ITIP20FactoryCalls::abi_decode,
20            |call| match call {
21                ITIP20FactoryCalls::createToken(call) => {
22                    mutate(call, msg_sender, |s, c| self.create_token(s, c))
23                }
24                ITIP20FactoryCalls::isTIP20(call) => view(call, |c| self.is_tip20(c.token)),
25                ITIP20FactoryCalls::getTokenAddress(call) => {
26                    view(call, |c| self.get_token_address(c))
27                }
28            },
29        )
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36    use crate::{
37        storage::{StorageCtx, hashmap::HashMapStorageProvider},
38        test_util::{assert_full_coverage, check_selector_coverage},
39    };
40    use tempo_contracts::precompiles::ITIP20Factory::ITIP20FactoryCalls;
41
42    #[test]
43    fn tip20_factory_test_selector_coverage() {
44        let mut storage = HashMapStorageProvider::new(1);
45
46        StorageCtx::enter(&mut storage, || {
47            let mut factory = TIP20Factory::new();
48
49            let unsupported = check_selector_coverage(
50                &mut factory,
51                ITIP20FactoryCalls::SELECTORS,
52                "ITIP20Factory",
53                ITIP20FactoryCalls::name_by_selector,
54            );
55
56            assert_full_coverage([unsupported]);
57        })
58    }
59}