Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

texa holdem pass #3247

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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 dev/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ if [ "$(uname -s)" == "Darwin" ]; then
sed -i "" 's/"enable_call": false/"enable_call": true/' $HOME_SERVER/config/genesis.json
sed -i "" 's/"enable_create": false/"enable_create": true/' $HOME_SERVER/config/genesis.json
sed -i "" 's/"enable_contract_blocked_list": false/"enable_contract_blocked_list": true/' $HOME_SERVER/config/genesis.json
sed -i "" 's/"max_gas_limit_per_tx": "30000000"/"max_gas_limit_per_tx": "20000000000"/' $HOME_SERVER/config/genesis.json
else
sed -i 's/"enable_call": false/"enable_call": true/' $HOME_SERVER/config/genesis.json
sed -i 's/"enable_create": false/"enable_create": true/' $HOME_SERVER/config/genesis.json
sed -i 's/"enable_contract_blocked_list": false/"enable_contract_blocked_list": true/' $HOME_SERVER/config/genesis.json
sed -i 's/"max_gas_limit_per_tx": "30000000"/"max_gas_limit_per_tx": "20000000000"/' $HOME_SERVER/config/genesis.json
fi

# Allocate genesis accounts (cosmos formatted addresses)
Expand Down
2 changes: 1 addition & 1 deletion dev/wasm/vmbridge-erc20/optimize-wasm.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.12.6
cosmwasm/rust-optimizer:0.12.11
214 changes: 171 additions & 43 deletions x/wasm/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package types

import (
"bytes"
"encoding/hex"
"encoding/json"
"github.com/okex/exchain/libs/tendermint/types/time"
"math/rand"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -171,51 +176,174 @@ func TestContractValidateBasic(t *testing.T) {
}
}

//func TestGenesisContractInfoMarshalUnmarshal(t *testing.T) {
// var myAddr sdk.WasmAddress = rand.Bytes(ContractAddrLen)
// var myOtherAddr sdk.WasmAddress = rand.Bytes(ContractAddrLen)
// anyPos := AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2}
// func TestGenesisContractInfoMarshalUnmarshal(t *testing.T) {
// var myAddr sdk.WasmAddress = rand.Bytes(ContractAddrLen)
// var myOtherAddr sdk.WasmAddress = rand.Bytes(ContractAddrLen)
// anyPos := AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2}
//
// anyTime := time.Now().UTC()
// // using gov proposal here as a random protobuf types as it contains an Any type inside for nested unpacking
// myExtension, err := govtypes.NewProposal(&govtypes.TextProposal{Title: "bar"}, 1, anyTime, anyTime)
// require.NoError(t, err)
// myExtension.TotalDeposit = nil
// anyTime := time.Now().UTC()
// // using gov proposal here as a random protobuf types as it contains an Any type inside for nested unpacking
// myExtension, err := govtypes.NewProposal(&govtypes.TextProposal{Title: "bar"}, 1, anyTime, anyTime)
// require.NoError(t, err)
// myExtension.TotalDeposit = nil
//
// src := NewContractInfo(1, myAddr, myOtherAddr, "bar", &anyPos)
// err = src.SetExtension(&myExtension)
// require.NoError(t, err)
// src := NewContractInfo(1, myAddr, myOtherAddr, "bar", &anyPos)
// err = src.SetExtension(&myExtension)
// require.NoError(t, err)
//
// interfaceRegistry := types.NewInterfaceRegistry()
// marshaler := codec.NewProtoCodec(interfaceRegistry)
// RegisterInterfaces(interfaceRegistry)
// // register proposal as extension type
// interfaceRegistry.RegisterImplementations(
// (*ContractInfoExtension)(nil),
// &govtypes.Proposal{},
// )
// // register gov types for nested Anys
// govtypes.RegisterInterfaces(interfaceRegistry)
// interfaceRegistry := types.NewInterfaceRegistry()
// marshaler := codec.NewProtoCodec(interfaceRegistry)
// RegisterInterfaces(interfaceRegistry)
// // register proposal as extension type
// interfaceRegistry.RegisterImplementations(
// (*ContractInfoExtension)(nil),
// &govtypes.Proposal{},
// )
// // register gov types for nested Anys
// govtypes.RegisterInterfaces(interfaceRegistry)
//
// // when encode
// gs := GenesisState{
// Contracts: []Contract{{
// ContractInfo: src,
// }},
// }
// // when encode
// gs := GenesisState{
// Contracts: []Contract{{
// ContractInfo: src,
// }},
// }
//
// bz, err := marshaler.Marshal(&gs)
// require.NoError(t, err)
// // and decode
// var destGs GenesisState
// err = marshaler.Unmarshal(bz, &destGs)
// require.NoError(t, err)
// // then
// require.Len(t, destGs.Contracts, 1)
// dest := destGs.Contracts[0].ContractInfo
// assert.Equal(t, src, dest)
// // and sanity check nested any
// var destExt govtypes.Proposal
// require.NoError(t, dest.ReadExtension(&destExt))
// assert.Equal(t, destExt.GetTitle(), "bar")
//}
// bz, err := marshaler.Marshal(&gs)
// require.NoError(t, err)
// // and decode
// var destGs GenesisState
// err = marshaler.Unmarshal(bz, &destGs)
// require.NoError(t, err)
// // then
// require.Len(t, destGs.Contracts, 1)
// dest := destGs.Contracts[0].ContractInfo
// assert.Equal(t, src, dest)
// // and sanity check nested any
// var destExt govtypes.Proposal
// require.NoError(t, dest.ReadExtension(&destExt))
// assert.Equal(t, destExt.GetTitle(), "bar")
// }
type Poker struct {
Poker struct {
UserHands []string `json:"user_hands"`
Board string `json:"board"`
} `json:"poker"`
}

func TestPoker(t *testing.T) {
//Card's Valid ranks: one of [23456789TJQKA]
//Card's Valid suits: one of [chsd]
ranks := []string{"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"}
suits := []string{"c", "h", "s", "d"}
ranksLen := len(ranks)
suitsLen := len(suits)
number := 5000
poker := Poker{Poker: struct {
UserHands []string `json:"user_hands"`
Board string `json:"board"`
}{
UserHands: make([]string, 0),
Board: "3c 5c As Jc Qh",
}}
s := rand.NewSource(time.Now().Unix())
for i := 0; i < number; i++ {
randSeed := rand.New(s).Int()

rankIndex_0 := randSeed % ranksLen
suitIndex_0 := randSeed % suitsLen
hands_0 := ranks[rankIndex_0] + suits[suitIndex_0]
for strings.Contains(poker.Poker.Board, hands_0) {
randSeed := rand.New(s).Int()
rankIndex_0 = randSeed % ranksLen
suitIndex_0 = randSeed % suitsLen
hands_0 = ranks[rankIndex_0] + suits[suitIndex_0]
}

rankIndex_1 := (randSeed + 1) % ranksLen
suitIndex_1 := (randSeed + 1) % suitsLen
hands_1 := ranks[rankIndex_1] + suits[suitIndex_1]
for strings.Contains(poker.Poker.Board+hands_0, hands_1) {
randSeed := rand.New(s).Int()
rankIndex_1 = (randSeed + 1) % ranksLen
suitIndex_1 = (randSeed + 1) % suitsLen
hands_1 = ranks[rankIndex_1] + suits[suitIndex_1]
}

hands := hands_0 + " " + hands_1
poker.Poker.UserHands = append(poker.Poker.UserHands, hands)
}
buff, err := json.Marshal(poker)
require.NoError(t, err)
t.Log("poker", string(buff))
t.Log("hex", hex.EncodeToString(buff))
}

type Poker2 struct {
Poker2 struct {
UserHands []string `json:"user_hands"`
Board string `json:"board"`
Num int `json:"num"`
} `json:"poker_multi"`
}

func TestPoker2(t *testing.T) {
//Card's Valid ranks: one of [23456789TJQKA]
//Card's Valid suits: one of [chsd]
ranks := []string{"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"}
suits := []string{"c", "h", "s", "d"}
ranksLen := len(ranks)
suitsLen := len(suits)
number := 5000
times := 10
poker := Poker2{Poker2: struct {
UserHands []string `json:"user_hands"`
Board string `json:"board"`
Num int `json:"num"`
}{
UserHands: make([]string, 0),
Board: "3c 5c As Jc Qh",
Num: times,
}}
s := rand.NewSource(time.Now().Unix())
for i := 0; i < number; i++ {
randSeed := rand.New(s).Int()

rankIndex_0 := randSeed % ranksLen
suitIndex_0 := randSeed % suitsLen
hands_0 := ranks[rankIndex_0] + suits[suitIndex_0]
for strings.Contains(poker.Poker2.Board, hands_0) {
randSeed := rand.New(s).Int()
rankIndex_0 = randSeed % ranksLen
suitIndex_0 = randSeed % suitsLen
hands_0 = ranks[rankIndex_0] + suits[suitIndex_0]
}

rankIndex_1 := (randSeed + 1) % ranksLen
suitIndex_1 := (randSeed + 1) % suitsLen
hands_1 := ranks[rankIndex_1] + suits[suitIndex_1]
for strings.Contains(poker.Poker2.Board+hands_0, hands_1) {
randSeed := rand.New(s).Int()
rankIndex_1 = (randSeed + 1) % ranksLen
suitIndex_1 = (randSeed + 1) % suitsLen
hands_1 = ranks[rankIndex_1] + suits[suitIndex_1]
}

hands := hands_0 + " " + hands_1
poker.Poker2.UserHands = append(poker.Poker2.UserHands, hands)
}
buff, err := json.Marshal(poker)
require.NoError(t, err)
t.Log("poker", string(buff))
t.Log("hex", hex.EncodeToString(buff))
}

func TestBase64(t *testing.T) {
str := "IFOmDgdWAT2B1MmGY9xDyHWi6Kha48B5J2\\/AZpckNkjq0zDPL9PQZeQeVRfhadn98QQNsHaeJEdUIEo0KEiN4wTYWeTrULpt3iUkbf+GV6RRxM8W87HaZEEi3vGV+auABVNWfBpAK9plZN+tCY4m9w=="
//dbuf, err := base64.StdEncoding.DecodeString(str)
//require.NoError(t, err)
//t.Log("dbuf-str:", string(dbuf))
//t.Log("dbuf-hex:", hex.EncodeToString(dbuf))
temp := []byte(str)
t.Log(hex.EncodeToString(temp))
}