code.vegaprotocol.io/vega@v0.79.0/core/bridges/erc20_asset_pool_test.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package bridges_test
    17  
    18  import (
    19  	"testing"
    20  
    21  	"code.vegaprotocol.io/vega/core/bridges"
    22  	"code.vegaprotocol.io/vega/libs/num"
    23  
    24  	"github.com/stretchr/testify/assert"
    25  )
    26  
    27  const (
    28  	erc20AssetPool = "0xcB84d72e61e383767C4DFEb2d8ff7f4FB89abc6e"
    29  )
    30  
    31  func TestAssetPoolSetBridgeAddress(t *testing.T) {
    32  	tcs := []struct {
    33  		name     string
    34  		v1       bool
    35  		expected string
    36  	}{
    37  		{
    38  			name:     "v1 scheme",
    39  			v1:       true,
    40  			expected: "d0d9cfac8f805bd28a8c534069157d900b8c60d29580ebbee73ad5be71d1d2c1b20d5f10339b0ff570cea9f3422c1c599bd76b99c37cd19c8a3901bd75603404",
    41  		},
    42  		{
    43  			name:     "v2 scheme",
    44  			v1:       false,
    45  			expected: "52e2d9005416e7afe750b4fcf69d9e8e0fe2809127f87c327f10cfa5e76da55069ef723cdc07bafcfb4e44798f2d1b52cf618787cbccf19c6c8f2d1cd0530906",
    46  		},
    47  	}
    48  
    49  	for _, tc := range tcs {
    50  		t.Run(tc.name, func(tt *testing.T) {
    51  			signer := testSigner{}
    52  			pool := bridges.NewERC20AssetPool(signer, erc20AssetPool, chainID, tc.v1)
    53  			sig, err := pool.SetBridgeAddress(
    54  				erc20AssetAddr,
    55  				num.NewUint(42),
    56  			)
    57  
    58  			assert.NoError(t, err)
    59  			assert.NotNil(t, sig.Message)
    60  			assert.NotNil(t, sig.Signature)
    61  			assert.True(t, signer.Verify(sig.Message, sig.Signature))
    62  			assert.Equal(t, tc.expected, sig.Signature.Hex())
    63  		})
    64  	}
    65  }