@@ -9,11 +9,16 @@ package evm
99import (
1010 "testing"
1111
12+ "github.com/LFDT-Panurus/panurus/token/services/network/driver"
13+ "github.com/LFDT-Panurus/panurus/x/token/services/network/evm/client/mock"
14+
15+ "github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1216 "github.com/stretchr/testify/assert"
1317 "github.com/stretchr/testify/require"
1418)
1519
16- // fakeResolver reports a fixed set of (network|channel) pairs as EVM networks.
20+ // fakeResolver reports a fixed set of (network|channel) pairs as EVM networks and yields a minimal
21+ // valid configuration for them.
1722type fakeResolver struct {
1823 evm map [string ]bool
1924}
@@ -22,6 +27,16 @@ func (f fakeResolver) IsEVMNetwork(network, channel string) bool {
2227 return f .evm [network + "|" + channel ]
2328}
2429
30+ func (f fakeResolver ) ConfigFor (network , channel string ) (* Config , error ) {
31+ if ! f .IsEVMNetwork (network , channel ) {
32+ return nil , errors .Errorf ("no evm configuration for [%s:%s]" , network , channel )
33+ }
34+ c := validConfig ()
35+ c .applyDefaults ()
36+
37+ return c , c .Validate ()
38+ }
39+
2540func TestDriverNewRouting (t * testing.T ) {
2641 d := & Driver {resolver : fakeResolver {evm : map [string ]bool {"evm-net|" : true }}}
2742
@@ -41,15 +56,40 @@ func TestDriverNewRouting(t *testing.T) {
4156 assert .Error (t , err )
4257}
4358
44- // TestNetworkStubNotImplemented documents that the skeleton's behavioural methods are wired to the
45- // interface but not yet implemented, so a mis-registration surfaces as a clear error rather than a
46- // nil-pointer panic.
47- func TestNetworkStubNotImplemented (t * testing.T ) {
48- n := newNetwork ("evm-net" )
59+ // TestNetworkSurfaceIsWired checks the methods that used to be stubs now answer through the finality
60+ // manager rather than returning a not-implemented error.
61+ func TestNetworkSurfaceIsWired (t * testing.T ) {
62+ evm := & mock.EVMClient {}
63+ // getTokenRequestHash returns the zero hash: the anchor has not been applied.
64+ evm .CallReturns (make ([]byte , 32 ), nil )
65+ n := testNetwork (t , evm , nil )
4966
5067 assert .NotNil (t , n .NewEnvelope ())
51- err := n .Broadcast (t .Context (), & Envelope {})
52- require .ErrorIs (t , err , errNotImplemented )
53- _ , err = n .Ledger ()
54- assert .ErrorIs (t , err , errNotImplemented )
68+
69+ ledger , err := n .Ledger ()
70+ require .NoError (t , err )
71+ require .NotNil (t , ledger )
72+
73+ // An anchor the chain has never seen is Unknown: never the invalid zero code, and never Invalid,
74+ // because a reverted apply is indistinguishable from one still pending (design 7.4).
75+ status , hash , _ , err := n .GetTransactionStatus (t .Context (), "token" , anchorHex (0x01 ))
76+ require .NoError (t , err )
77+ assert .Equal (t , driver .Unknown , status )
78+ assert .Nil (t , hash )
79+
80+ code , err := ledger .Status (anchorHex (0x01 ))
81+ require .NoError (t , err )
82+ assert .Equal (t , driver .Unknown , code )
83+ }
84+
85+ // TestNetworkRejectsMalformedTransactionID checks the anchor-shaped identifier is validated rather
86+ // than silently producing a wrong on-chain lookup.
87+ func TestNetworkRejectsMalformedTransactionID (t * testing.T ) {
88+ n := testNetwork (t , nil , nil )
89+
90+ _ , _ , _ , err := n .GetTransactionStatus (t .Context (), "token" , "not-a-valid-anchor" )
91+ require .Error (t , err )
92+
93+ err = n .AddFinalityListener ("token" , "not-a-valid-anchor" , nil )
94+ require .Error (t , err )
5595}
0 commit comments